Advertisement
SasnycoN

CheckPointInCircle1

Jan 11th, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 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 CheckPointInCircle1
  8. (
  9. class CheckPointInCircle1
  10.     {
  11.         static void Main()
  12.         {
  13.             //(x-a)^2 + (y-b)^2 = r^2
  14.             //x^2 == x*x
  15.             //We need first part to be equal or small than the second,
  16.             //becouse we looking for a point IN the circle.
  17.             //The points on the perimeter of the circle ARE in it!
  18.  
  19.             double radiusR = 5;
  20.             double circleX = 0;
  21.             double circleY = 0;
  22.            
  23.             Console.WriteLine(@"Checking if given point (x,  y) is within a circle K(O, 5)...");
  24.            
  25.             Console.Write(@"Please Provide ""x"": ");
  26.             double pointX = double.Parse(Console.ReadLine());
  27.            
  28.             Console.Write(@"Please Provide ""y"": ");
  29.             double pointY = double.Parse(Console.ReadLine());
  30.  
  31.             double checkX = (pointX - circleX) * (pointX - circleX); //(x-a)^2
  32.             double checkY = (pointY - circleY) * (pointY - circleY); //(y-b)^2
  33.             double xyCheck = (checkX + checkY);                      //(x-a)^2 + (y-b)^2
  34.             double rCheck = (radiusR * radiusR);                     //r^2
  35.  
  36.             if (xyCheck <= rCheck)
  37.                 {
  38.                     Console.WriteLine("The pоint IS in the circle!");
  39.                 }
  40.             else
  41.                 {
  42.                     Console.WriteLine("The point IS NOT in the circle!");
  43.                 }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement