Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. //
  2. // main.cpp
  3. // Точка пересечения прямых
  4. //
  5. // Created by Владислав on 17/07/2019.
  6. // Copyright © 2019 Владислав. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10.  
  11. using namespace std;
  12.  
  13. double x1, y1, x2, y2, x3, y3, x4, y4, a1, b1, c1, a2, b2, c2, x, y;
  14.  
  15. int main() {
  16. cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
  17. a1 = y1 - y2;
  18. b1 = x2 - x1;
  19. c1 = x1 * y2 - x2 * y1;
  20. a2 = y3 - y4;
  21. b2 = x4 - x3;
  22. c2 = x3 * y4 - x4 * y3;
  23. if(a1 * b2 - a2 * b1 == 0) {
  24. if(a1 * c2 - a2 * c1 == 0 && b1 * c2 - b2 * c1 == 0 ) {
  25. cout << 2 << '\n';
  26. } else {
  27. cout << 0 << '\n';
  28. }
  29. } else {
  30. x = (((c1 * b2) - (c2 * b1)) / ((a1 * b2) - (a2 * b1)));
  31. y = (((a1 * c2) -(a2 * c1)) / ((a1 * b2) - (a2 * b1)));
  32. x *= -1;
  33. y *= -1;
  34. if(a1 == a2 && b1 == b2 && c1 == c2) {
  35. cout << 2 << '\n';
  36. } else {
  37. cout.precision(15);
  38. cout << fixed << 1 << " " << x << " " << y << '\n';
  39. }
  40. }
  41.  
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement