Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
389
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 _03.Intersection_of_Circles
  8. {
  9.     public class Circle
  10.     {
  11.         public double Raduis { get; set; }
  12.         public double x1 { get; set; }
  13.         public double y1 { get; set; }
  14.     }
  15.    
  16.     class Program
  17.     {
  18.         static void Main()
  19.         {
  20.             var xYandRadusC1 = Console.ReadLine().Split().Select(double.Parse).ToList();
  21.             var xYandRadusC2 = Console.ReadLine().Split().Select(double.Parse).ToList();
  22.  
  23.            
  24.             Circle firstCircle = new Circle();
  25.             firstCircle.x1 = xYandRadusC1[0];
  26.             firstCircle.y1 = xYandRadusC1[1];
  27.             firstCircle.Raduis = xYandRadusC1[2];
  28.            
  29.  
  30.             Circle secondCircle = new Circle();
  31.             secondCircle.x1 = xYandRadusC2[0];
  32.             secondCircle.y1 = xYandRadusC2[1];
  33.             secondCircle.Raduis = xYandRadusC2[2];
  34.  
  35.             if (Intersect(firstCircle, secondCircle))
  36.             {
  37.                 Console.WriteLine("Yes");
  38.             }
  39.             else
  40.             {
  41.                 Console.WriteLine("No");
  42.             }            
  43.         }
  44.         private static bool Intersect(Circle firstCircle, Circle secondCircle)
  45.         {
  46.            
  47.             double distance = 0;
  48.             distance = Math.Sqrt(Math.Pow(secondCircle.x1 - firstCircle.x1, 2) + Math.Pow(secondCircle.y1 - firstCircle.y1, 2));
  49.             if (distance <= firstCircle.Raduis + secondCircle.Raduis)
  50.             {
  51.                 return true;
  52.             }
  53.             else if (distance > firstCircle.Raduis + secondCircle.Raduis)
  54.             {
  55.                 return false;
  56.             }
  57.             return false;
  58.         }
  59.  
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement