Advertisement
Guest User

CirclesIntersection

a guest
Oct 17th, 2017
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _03.CirclesIntersection
  5. {
  6.     class StartUp
  7.     {
  8.         static void Main()
  9.         {
  10.             int[] firstCircle = Console.ReadLine().Split().Select(int.Parse).ToArray();
  11.             int[] secondCircle = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.  
  13.             Circle c1 = new Circle();
  14.             c1.Radius = firstCircle[2];
  15.             Point c1Center = new Point();
  16.             c1Center.x = firstCircle[0];
  17.             c1Center.y = firstCircle[1];
  18.  
  19.             Circle c2 = new Circle();
  20.             c2.Radius = secondCircle[2];
  21.             Point c2Center = new Point();
  22.             c2Center.x = secondCircle[0];
  23.             c2Center.y = secondCircle[1];
  24.  
  25.             double distance = CalcDistance(c1Center, c2Center);
  26.             if (Intersect(c1, c2, distance))
  27.             {
  28.                 Console.WriteLine("Yes");
  29.             }
  30.             else
  31.             {
  32.                 Console.WriteLine("No");
  33.             }
  34.         }
  35.  
  36.         private static double CalcDistance(Point c1Center, Point c2Center)
  37.         {
  38.             double distance = Math.Sqrt(Math.Pow((c1Center.x - c2Center.x), 2) + Math.Pow((c1Center.y - c2Center.y), 2));
  39.  
  40.             return distance;
  41.         }
  42.  
  43.         static bool Intersect(Circle c1, Circle c2,double distance)
  44.         {
  45.             if (distance <= c1.Radius + c2.Radius)
  46.             {
  47.                 return true;
  48.             }
  49.             return false;
  50.         }
  51.     }
  52.  
  53.     class Circle
  54.     {
  55.         public double Center { get; set; }
  56.    
  57.         public double Radius { get; set; }
  58.     }
  59.  
  60.     class Point
  61.     {
  62.         public int x { get; set; }
  63.  
  64.         public int y { get; set; }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement