Advertisement
bacco

Intersection of Circles

Jul 2nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4.  
  5.  
  6. class Point
  7. {
  8.     public int X { get; set; }
  9.     public int Y { get; set; }
  10.  
  11.  
  12.     public Point( int x, int y)
  13.     {
  14.         X = x;
  15.         Y = y;
  16.     }
  17.  
  18.     public static int calculateDistance(Point p1, Point p2)
  19.     {
  20.         return (int)Math.Sqrt(Math.Pow(p2.X - p1.X, 2) + Math.Pow(p2.Y - p1.Y, 2));
  21.     }
  22. }
  23.  
  24.  
  25. class Circle
  26. {
  27.     public int Radius { get; set; }
  28.     public Point Center { get; set; }
  29.  
  30.     public Circle(Point center, int radius)
  31.     {
  32.         Center = center;
  33.         Radius = radius;
  34.     }
  35.  
  36.     public static bool Intersect( Circle c1, Circle c2)
  37.     {
  38.         int d = Point.calculateDistance(c1.Center, c2.Center);
  39.  
  40.         if (d <= c1.Radius + c2.Radius)
  41.         {
  42.             return true;
  43.         }
  44.         return false;
  45.     }
  46. }
  47.  
  48. public class Example
  49. {
  50.     public static void Main()
  51.     {
  52.         int[] firstCircle  = Console.ReadLine().Split().Select(int.Parse).ToArray();
  53.         int[] secondCircle = Console.ReadLine().Split().Select(int.Parse).ToArray();
  54.  
  55.         Point firstPoint  = new Point(firstCircle[0],  firstCircle[1]);
  56.         Point secondPoint = new Point(secondCircle[0], secondCircle[1]);
  57.  
  58.         Circle circleOne  = new Circle(firstPoint, firstCircle[2]);
  59.         Circle circleTwo = new Circle(secondPoint, secondCircle[2]);
  60.  
  61.         if (Circle.Intersect(circleOne, circleTwo))
  62.         {
  63.             Console.WriteLine("Yes");
  64.         }
  65.         else
  66.         {
  67.             Console.WriteLine("No");
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement