Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _03._Longer_Line
- {
- class Program
- {
- static void Main(string[] args)
- {
- double x1CloserToZeroPoint = 0;
- double y1CloserToZeroPoint = 0;
- double x2SecondPoint = 0;
- double y2SecondPoint = 0;
- double hypotenuse = double.MinValue;
- for (int i = 1; i <= 2; i++)
- {
- double x1 = double.Parse(Console.ReadLine());
- double y1 = double.Parse(Console.ReadLine());
- double x2 = double.Parse(Console.ReadLine());
- double y2 = double.Parse(Console.ReadLine());
- double tempX1CloserToZeroPoint = x1;
- double tempY1CloserToZeroPoint = y1;
- double tempX2SecondPoint = x2;
- double tempY2SecondPoint = y2;
- // 01. уточняване разстоянието между p1 and p1
- double tempHypotenuse = GetDistanceBetweenTwoPoints(x1, y1, x2, y2);
- // 02. уточняване на по-близката точка до 0
- // метода ще провери дали р1 е по-близко до 0, 0
- // ако е така ще върне true - иначе ще върне false
- // а ние ще трябва да разменим местата на р1 и р2 в tempКоординатите
- bool p1IsTheCloserPointToZero = GetP1IsCloserToTheZeroPoint(x1, y1, x2, y2);
- if (!p1IsTheCloserPointToZero)
- {
- tempX1CloserToZeroPoint = x2;
- tempY1CloserToZeroPoint = y2;
- tempX2SecondPoint = x1;
- tempY2SecondPoint = y1;
- }
- if (hypotenuse < tempHypotenuse)
- {
- x1CloserToZeroPoint = tempX1CloserToZeroPoint;
- y1CloserToZeroPoint = tempY1CloserToZeroPoint;
- x2SecondPoint = tempX2SecondPoint;
- y2SecondPoint = tempY2SecondPoint;
- }
- }
- Console.WriteLine($"({x1CloserToZeroPoint}, {y1CloserToZeroPoint})({x2SecondPoint}, {y2SecondPoint})");
- //Console.WriteLine("Hello World!");
- }
- private static double GetDistanceBetweenTwoPoints(double x1, double y1, double x2, double y2)
- {
- double sideA = Math.Abs(x2 - x1);
- double sideB = Math.Abs(y2 - y1);
- double sideC = Math.Sqrt((sideA * sideA) + (sideB * sideB));
- return sideC;
- }
- private static bool GetP1IsCloserToTheZeroPoint(double x1, double y1, double x2, double y2)
- {
- double c1 = GetHypotenuse(x1, y1);
- double c2 = GetHypotenuse(x2, y2);
- bool result = true;
- if (c2 < c1)
- {
- result = false;
- }
- return result;
- }
- private static double GetHypotenuse(double a, double b)
- {
- //a = Math.Abs(a);
- //b = Math.Abs(b);
- double c = Math.Sqrt((a * a) + (b * b));
- return c;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement