Advertisement
SavaIv

Untitled

May 29th, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _03._Longer_Line
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. double x1CloserToZeroPoint = 0;
  10. double y1CloserToZeroPoint = 0;
  11. double x2SecondPoint = 0;
  12. double y2SecondPoint = 0;
  13. double hypotenuse = double.MinValue;
  14.  
  15. for (int i = 1; i <= 2; i++)
  16. {
  17. double x1 = double.Parse(Console.ReadLine());
  18. double y1 = double.Parse(Console.ReadLine());
  19. double x2 = double.Parse(Console.ReadLine());
  20. double y2 = double.Parse(Console.ReadLine());
  21.  
  22. double tempX1CloserToZeroPoint = x1;
  23. double tempY1CloserToZeroPoint = y1;
  24. double tempX2SecondPoint = x2;
  25. double tempY2SecondPoint = y2;
  26.  
  27. // 01. уточняване разстоянието между p1 and p1
  28. double tempHypotenuse = GetDistanceBetweenTwoPoints(x1, y1, x2, y2);
  29.  
  30. // 02. уточняване на по-близката точка до 0
  31. // метода ще провери дали р1 е по-близко до 0, 0
  32. // ако е така ще върне true - иначе ще върне false
  33. // а ние ще трябва да разменим местата на р1 и р2 в tempКоординатите
  34. bool p1IsTheCloserPointToZero = GetP1IsCloserToTheZeroPoint(x1, y1, x2, y2);
  35.  
  36. if (!p1IsTheCloserPointToZero)
  37. {
  38. tempX1CloserToZeroPoint = x2;
  39. tempY1CloserToZeroPoint = y2;
  40. tempX2SecondPoint = x1;
  41. tempY2SecondPoint = y1;
  42. }
  43.  
  44. if (hypotenuse < tempHypotenuse)
  45. {
  46. x1CloserToZeroPoint = tempX1CloserToZeroPoint;
  47. y1CloserToZeroPoint = tempY1CloserToZeroPoint;
  48. x2SecondPoint = tempX2SecondPoint;
  49. y2SecondPoint = tempY2SecondPoint;
  50. }
  51. }
  52.  
  53. Console.WriteLine($"({x1CloserToZeroPoint}, {y1CloserToZeroPoint})({x2SecondPoint}, {y2SecondPoint})");
  54.  
  55. //Console.WriteLine("Hello World!");
  56. }
  57.  
  58. private static double GetDistanceBetweenTwoPoints(double x1, double y1, double x2, double y2)
  59. {
  60. double sideA = Math.Abs(x2 - x1);
  61. double sideB = Math.Abs(y2 - y1);
  62.  
  63. double sideC = Math.Sqrt((sideA * sideA) + (sideB * sideB));
  64.  
  65.  
  66. return sideC;
  67. }
  68.  
  69. private static bool GetP1IsCloserToTheZeroPoint(double x1, double y1, double x2, double y2)
  70. {
  71. double c1 = GetHypotenuse(x1, y1);
  72. double c2 = GetHypotenuse(x2, y2);
  73.  
  74. bool result = true;
  75.  
  76. if (c2 < c1)
  77. {
  78. result = false;
  79. }
  80.  
  81. return result;
  82.  
  83. }
  84.  
  85. private static double GetHypotenuse(double a, double b)
  86. {
  87. //a = Math.Abs(a);
  88. //b = Math.Abs(b);
  89.  
  90. double c = Math.Sqrt((a * a) + (b * b));
  91.  
  92. return c;
  93. }
  94.  
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement