Advertisement
gospod1978

Methods-Ex\More\Longer Line

Oct 14th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5.  
  6. namespace methods_exerci
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.  
  13.             double point1X = double.Parse(Console.ReadLine());
  14.             double point1Y = double.Parse(Console.ReadLine());
  15.             double point2X = double.Parse(Console.ReadLine());
  16.             double point2Y = double.Parse(Console.ReadLine());
  17.             double point3x = double.Parse(Console.ReadLine());
  18.             double point3Y = double.Parse(Console.ReadLine());
  19.             double point4X = double.Parse(Console.ReadLine());
  20.             double point4Y = double.Parse(Console.ReadLine());
  21.  
  22.             printLongerLine(point1X, point1Y, point2X, point2Y, point3x, point3Y, point4X, point4Y);
  23.         }
  24.  
  25.         static double lineLength(double x1, double y1, double x2, double y2)
  26.         {
  27.             return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
  28.         }
  29.  
  30.         static double distanceToCenter(double x, double y)
  31.         {
  32.             return Math.Sqrt(Math.Pow((0 - x), 2) + Math.Pow((0 - y), 2));
  33.         }
  34.  
  35.         static void printClosestPointFirst(double x1, double y1, double x2, double y2)
  36.         {
  37.             if (distanceToCenter(x1, y1) > distanceToCenter(x2, y2))
  38.             {
  39.                 Console.Write("(" + x2 + ", " + y2 + ")");
  40.                 Console.WriteLine("(" + x1 + ", " + y1 + ")");
  41.             }
  42.             else
  43.             {
  44.                 Console.Write("(" + x1 + ", " + y1 + ")");
  45.                 Console.WriteLine("(" + x2 + ", " + y2 + ")");
  46.             }
  47.         }
  48.  
  49.         static void printLongerLine(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
  50.         {
  51.             if (lineLength(x1, y1, x2, y2) >= lineLength(x3, y3, x4, y4))
  52.             {
  53.                 printClosestPointFirst(x1, y1, x2, y2);
  54.             }
  55.             else if (lineLength(x1, y1, x2, y2) < lineLength(x3, y3, x4, y4))
  56.             {
  57.                 printClosestPointFirst(x3, y3, x4, y4);
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement