Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- double dist (double x1, double y1, double x2, double y2)
- {
- return (sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
- }
- int main()
- {
- double a1, b1, c1, a2, b2, c2, x1, y1, x2, y2, x3, y3, x4, y4, x, y;
- cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
- if (x1 > x2)
- {
- swap(x1, x2);
- swap(y1, y2);
- }
- if (x1 == x2 && y1 > y2)
- swap(y1, y2);
- if (x3 > x4)
- {
- swap(x3, x4);
- swap(y3, y4);
- }
- if (x3 == x4 && y3 > y4)
- swap(y3, y4);
- if (x3 < x1 || x1 == x3 && y1 > y3) {
- swap(x1, x3);
- swap(y1, y3);
- swap(x2, x4);
- swap(y2, y4);
- }
- a1 = y2 - y1;
- b1 = -x2 + x1;
- c1 = y1 * x2 - x1 * y2;
- a2 = y4 - y3;
- b2 = -x4 + x3;
- c2 = y3 * x4 - x3 * y4;
- if (a1 * b2 == b1 * a2 && c1 * a2 != c2 * a1 && c1 * b2 != c2 * b1)
- {
- cout << "Empty";
- return 0;
- }
- if (a1 * b2 == b1 * a2 && c1 * a2 == c2 * a1 && c1 * b2 == c2 * b1)
- {
- if (x3 == x2) {
- if (y3 == y2) {
- printf("%.6f %.6f", x3, y3);
- return 0;
- }
- else {
- if (y3 < y2) {
- if (y4 <= y2) {
- if (dist(x3, y3, x4, y4) == 0) {
- printf("%.6f %.6f", x3, y3);
- }
- else {
- printf("%.6f %.6f %.6f %.6f", x3, y3, x4, y4);
- }
- }
- else {
- printf("%.6f %.6f %.6f %.6f", x3, y3, x2, y2);
- }
- return 0;
- }
- }
- }
- if (x3 < x2) {
- if (x4 <= x2) {
- if (dist(x3, y3, x4, y4) == 0) {
- printf("%.6f %.6f", x3, y3);
- }
- else {
- printf("%.6f %.6f %.6f %.6f", x3, y3, x4, y4);
- }
- }
- else {
- printf("%.6f %.6f %.6f %.6f", x3, y3, x2, y2);
- }
- return 0;
- }
- cout << "Empty";
- return 0;
- }
- x = -(b2 * c1 - b1 * c2) / (a1 * b2 - a2 * b1);
- y = -(a1 * c2 - a2 * c1) / (a1 * b2 - a2 * b1);
- if (x <= max(x2, x1) && x >= min(x1, x2) && y <= max(y2, y1) && y >= min(y1, y2) && x <= max(x4, x3) && x >= min(x3, x4) && y <= max(y4, y3) && y >= min(y3, y4))
- {
- printf("%.6f", x);
- cout << "\n";
- printf("%.6f", y);
- }
- else
- cout << "Empty";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement