Advertisement
martinvalchev

Circles_Intersection

Feb 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Circles_Intersection
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double[] input = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
  14.             Circle circle = new Circle();
  15.             circle.Center = new Point();
  16.             circle.Center.X = input[0];
  17.             circle.Center.Y = input[1];
  18.             circle.Radius = input[2];
  19.             input = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
  20.             Circle circle2 = new Circle();
  21.             circle2.Center = new Point();
  22.             circle2.Center.X = input[0];
  23.             circle2.Center.Y = input[1];
  24.             circle2.Radius = input[2];
  25.             circle.IsIntersected(circle2);
  26.  
  27.             if (circle.IsIntersected(circle2))
  28.             {
  29.                 Console.WriteLine("Yes");
  30.             }
  31.             else
  32.             {
  33.                 Console.WriteLine("No");
  34.             }
  35.  
  36.         }
  37.     }
  38.  
  39.     class Point
  40.     {
  41.         public double X { get; set; }
  42.         public double Y { get; set; }
  43.     }
  44.  
  45.     class Circle
  46.     {
  47.         public Point Center { get; set; }
  48.         public double Radius { get; set; }
  49.  
  50.        public bool IsIntersected(Circle circle)
  51.         {
  52.             double distance = Math.Sqrt(Math.Abs(circle.Center.X - Center.X) * (Math.Abs(circle.Center.X - Center.X)
  53.                 + Math.Abs(circle.Center.Y - Center.Y) * Math.Abs(circle.Center.Y - Center.Y)));
  54.             if (distance <= circle.Radius + Radius)
  55.             {
  56.                 return true;
  57.             }
  58.             else
  59.             {
  60.                 return false;
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement