Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdio>
- #include<cmath>
- using namespace std;
- double triangleSquare(double x1,double y1,double x2,double y2){
- return abs(x1*y2 - x2*y1)/2.0;
- }
- struct Point{
- double x = .0,y = .0;
- double distanceTo(Point point){
- return sqrt(sqrt((point.x - x)*(point.x - x) + (point.y - y)*(point.y - y)));
- }
- bool operator == (const Point &point) const {
- return this->x == point.x && this->y == point.y;
- }
- };
- struct Polygone{
- Point * points;
- int numOfVert;
- bool isIncludesIn(Polygone p){
- bool isIncludes = 1;
- int n = numOfVert, m = p.numOfVert;
- for(int i = 0;i < n;i++){
- Point P = points[i];
- double S = .0;
- for(int j = 0;j < m-1;++j){
- S += triangleSquare(p.points[j].x - P.x,p.points[j].y - P.y,
- p.points[j+1].x - P.x,p.points[j+1].y - P.y);
- }
- S += triangleSquare(p.points[m-1].x - P.x,p.points[m-1].y - P.y,
- p.points[0].x - P.x,p.points[0].y - P.y);
- isIncludes *= (abs(S - p.square()) < 1e-9);
- }
- return isIncludes;
- }
- double square(){
- double S = .0;
- for(int i = 1;i < numOfVert-1;++i){
- S+= triangleSquare(points[i].x-points[0].x,points[i].y-points[0].y,
- points[i+1].x-points[0].x,points[i+1].y-points[0].y);
- }
- return S;
- }
- };
- int main(){
- int n;
- cout << "Введите кол-во вершин первого многоугольника\n";
- cin >> n;
- cout << "Вводите вершины в виде точек с координатами (x,y) в порядке обхода многоугольника по/против часовой стрелки\n"
- Polygne p1,p2;
- p1.points = new Point[n];
- p1.numOfVert = n;
- for(int i = 0;i < n;++i){
- cin >> p1.points[i].x >> p1.points[i].y;
- }
- int m;
- cout << "Введите кол-во вершин второго многоугольника\n";
- cin >> m;
- cout << "Вводите вершины в виде точек с координатами (x,y) в порядке обхода многоугольника по/против часовой стрелки\n"
- p2.points = new Point[m];
- p2.numOfVert = m;
- for(int i = 0;i < m;++i){
- cin >> p2.points[i].x >> p2.points[i].y;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement