Advertisement
NHumme

Untitled

Mar 31st, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 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. a1 = y2 - y1;
  29. b1 = -x2 + x1;
  30. c1 = y1 * x2 - x1 * y2;
  31. a2 = y4 - y3;
  32. b2 = -x4 + x3;
  33. c2 = y3 * x4 - x3 * y4;
  34. if (a1 * b2 == b1 * a2 && c1 * a2 != c2 * a1 && c1 * b2 != c2 * b1)
  35. {
  36. cout << "Empty";
  37. return 0;
  38. }
  39. if (a1 * b2 == b1 * a2 && c1 * a2 == c2 * a1 && c1 * b2 == c2 * b1)
  40. {
  41. if (x3 <= x2 && x3 >= x1 && y3 <= y2 && y3 >= y1)
  42. {
  43. if (dist(x3, y3, x2, y2) < dist(x3, y3, x4, y4))
  44. {
  45. if (dist(x3, y3, x2, y2) == 0)
  46. {
  47. printf("%.6f", x3);
  48. cout << "\n";
  49. printf("%.6f", y3);
  50. return 0;
  51. }
  52. printf("%.6f", x3);
  53. cout << "\n";
  54. printf("%.6f", y3);
  55. cout << "\n";
  56. printf("%.6f", x2);
  57. cout << "\n";
  58. printf("%.6f", y2);
  59. }
  60. else
  61. {
  62. if (dist(x3, y3, x4, y4) == 0)
  63. {
  64. printf("%.6f", x3);
  65. cout << "\n";
  66. printf("%.6f", y3);
  67. return 0;
  68. }
  69. printf("%.6f", x3);
  70. cout << "\n";
  71. printf("%.6f", y3);
  72. cout << "\n";
  73. printf("%.6f", x4);
  74. cout << "\n";
  75. printf("%.6f", y4);
  76. }
  77. return 0;
  78. }
  79. if (x4 <= x2 && x4 >= x1 && y4 <= y2 && y4 >= y1)
  80. {
  81. if (dist(x4, y4, x1, y1) < dist(x3, y3, x4, y4))
  82. {
  83. if (dist(x4, y4, x1, y1) == 0)
  84. {
  85. printf("%.6f", x4);
  86. cout << "\n";
  87. printf("%.6f", y4);
  88. return 0;
  89. }
  90. printf("%.6f", x1);
  91. cout << "\n";
  92. printf("%.6f", y1);
  93. cout << "\n";
  94. printf("%.6f", x4);
  95. cout << "\n";
  96. printf("%.6f", y4);
  97. }
  98. else
  99. {
  100. if (dist(x4, y4, x3, y3) == 0)
  101. {
  102. printf("%.6f", x4);
  103. cout << "\n";
  104. printf("%.6f", y4);
  105. return 0;
  106. }
  107. printf("%.6f", x3);
  108. cout << "\n";
  109. printf("%.6f", y3);
  110. cout << "\n";
  111. printf("%.6f", x4);
  112. cout << "\n";
  113. printf("%.6f", y4);
  114. }
  115. return 0;
  116. }
  117. cout << "Empty";
  118. return 0;
  119. }
  120. x = -(b2 * c1 - b1 * c2) / (a1 * b2 - a2 * b1);
  121. y = -(a1 * c2 - a2 * c1) / (a1 * b2 - a2 * b1);
  122. 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))
  123. {
  124. printf("%.6f", x);
  125. cout << "\n";
  126. printf("%.6f", y);
  127. }
  128. else
  129. cout << "Empty";
  130. return 0;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement