Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> //exercise 6
- #include <string> //there is a set of points on the plane
- #include <vector> //find all points which is in rectangle formed by {x1,y1} {x2,y2} {x3,y3} {x4,y4}
- #include <algorithm>
- using namespace std;
- struct dot
- {
- int x, y;
- dot(int a, int b) : x(a), y(b) {};
- };
- vector<dot> DOT;
- double sideLength(int a, int b)
- {
- return sqrt((DOT[a].x - DOT[b].x) * (DOT[a].x - DOT[b].x) + (DOT[a].y - DOT[b].y) * (DOT[a].y- DOT[b].y));
- }
- double squareTriangle(int a, int b, int c)
- {
- double side1 = sideLength(a, b);
- double side2 = sideLength(b, c);
- double side3 = sideLength(c, a);
- double p = (side1 + side2 + side3) / 2;
- double square = sqrt(p * (p - side1) * (p - side2) * (p - side3));
- return square;
- }
- int main()
- {
- int a, b, counter = 0;
- cout << "Please, input the coordinates of rectangle in true way: like clockwise or counter-clockwise" << endl;
- for(int i = 0; i < 4; i++)
- {
- cout << "Enter the x" << i + 1 << " and y" << i + 1 << endl;
- cin >> a >> b;
- DOT.push_back(dot(a, b));
- }
- cout << "Enter coordinates of other dots. End the input by typing a letter." << endl;
- while(cin >> a)
- {
- cin >> b;
- DOT.push_back(dot(a, b));
- cout << "Coordinates of this dot are " << DOT.back().x << "," << DOT.back().y << endl;
- counter++;
- }
- double eps = 0.000001;
- double square = sideLength(0, 1) * sideLength(2, 1);
- bool was = false;
- for(int i = 0; i < counter; i++)
- {
- double squareSum = squareTriangle(0, 1, i + 4) + squareTriangle(1, 2, i + 4) + squareTriangle(2, 3, i + 4) + squareTriangle(3, 0, i + 4);
- if (abs(squareSum - square) < eps)
- {
- cout << "Lucky dot is " << DOT[i + 4].x << "," << DOT[i + 4].y << endl;
- was = true;
- }
- }
- if(!was)
- cout << "No lucky dots\n";
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement