Advertisement
NHumme

Untitled

Mar 31st, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. double dist (double x1, double y1, double x2, double y2)
  6. {
  7. return (sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
  8. }
  9.  
  10. int main()
  11. {
  12. double a1, b1, c1, a2, b2, c2, x1, y1, x2, y2, x3, y3, x4, y4, x, y;
  13. cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
  14. if (x1 > x2)
  15. {
  16. swap(x1, x2);
  17. swap(y1, y2);
  18. }
  19. if (x1 == x2 && y1 > y2)
  20. swap(y1, y2);
  21. if (x3 > x4)
  22. {
  23. swap(x3, x4);
  24. swap(y3, y4);
  25. }
  26. if (x3 == x4 && y3 > y4)
  27. swap(y3, y4);
  28. if (x3 < x1 || x1 == x3 && y1 > y3) {
  29. swap(x1, x3);
  30. swap(y1, y3);
  31. swap(x2, x4);
  32. swap(y2, y4);
  33. }
  34.  
  35. a1 = y2 - y1;
  36. b1 = -x2 + x1;
  37. c1 = y1 * x2 - x1 * y2;
  38. a2 = y4 - y3;
  39. b2 = -x4 + x3;
  40. c2 = y3 * x4 - x3 * y4;
  41. if (a1 * b2 == b1 * a2 && c1 * a2 != c2 * a1 && c1 * b2 != c2 * b1)
  42. {
  43. cout << "Empty";
  44. return 0;
  45. }
  46. if (a1 * b2 == b1 * a2 && c1 * a2 == c2 * a1 && c1 * b2 == c2 * b1)
  47. {
  48. if (x3 == x2) {
  49. if (y3 == y2) {
  50. printf("%.6f %.6f", x3, y3);
  51. return 0;
  52. }
  53. else {
  54. if (y3 < y2) {
  55. if (y4 <= y2) {
  56. if (dist(x3, y3, x4, y4) == 0) {
  57. printf("%.6f %.6f", x3, y3);
  58. }
  59. else {
  60. printf("%.6f %.6f %.6f %.6f", x3, y3, x4, y4);
  61. }
  62. }
  63. else {
  64. printf("%.6f %.6f %.6f %.6f", x3, y3, x2, y2);
  65. }
  66. return 0;
  67. }
  68. }
  69. }
  70. if (x3 < x2) {
  71. if (x4 <= x2) {
  72. if (dist(x3, y3, x4, y4) == 0) {
  73. printf("%.6f %.6f", x3, y3);
  74. }
  75. else {
  76. printf("%.6f %.6f %.6f %.6f", x3, y3, x4, y4);
  77. }
  78. }
  79. else {
  80. printf("%.6f %.6f %.6f %.6f", x3, y3, x2, y2);
  81. }
  82. return 0;
  83. }
  84. cout << "Empty";
  85. return 0;
  86. }
  87. x = -(b2 * c1 - b1 * c2) / (a1 * b2 - a2 * b1);
  88. y = -(a1 * c2 - a2 * c1) / (a1 * b2 - a2 * b1);
  89. 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))
  90. {
  91. printf("%.6f", x);
  92. cout << "\n";
  93. printf("%.6f", y);
  94. }
  95. else
  96. cout << "Empty";
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement