SkyWatcher

Point Inside a Circle & Outside a Rectangle

Mar 30th, 2014
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.36 KB | None | 0 0
  1. using System;
  2. class PointInsideCircleOutsideRectangle
  3. {
  4.     static void Main()
  5.     {
  6.         Console.WriteLine("Point Inside a Circle & Outside a Rectangle");
  7.        
  8.         bool check;
  9.  
  10.         Console.WriteLine("\n" + "Please, set a position (xo, yo) of the circle K, as follow:");
  11.  
  12.         Console.Write("\n" + "Horzontal coordinate \"xo\": ");
  13.         double xo = double.Parse(Console.ReadLine());
  14.  
  15.         Console.Write("Vertical coordinate  \"yo\": ");
  16.         double yo = double.Parse(Console.ReadLine());
  17.        
  18.         Console.Write("\n" + "Please, enter the circle radius: ");
  19.         double R = double.Parse(Console.ReadLine());
  20.  
  21.         Console.WriteLine("\n" + "Please, determine the borders of the rectangle R, as follow:");
  22.  
  23.         Console.Write("\n" + "Left vertical border \"xMin\": ");
  24.         double xMin = double.Parse(Console.ReadLine());
  25.        
  26.         Console.Write("Right vertical border \"xMax\": ");
  27.         double xMax = double.Parse(Console.ReadLine());
  28.  
  29.         double width = xMax - xMin;
  30.  
  31.         Console.Write("\n" + "Lower horizontal border \"yMin\": ");
  32.         double yMin = double.Parse(Console.ReadLine());
  33.  
  34.         Console.Write("Upper horizontal border \"yMax\": ");
  35.         double yMax = double.Parse(Console.ReadLine());
  36.  
  37.         double height = yMax - yMin;
  38.  
  39.         Console.Write("\n" + "Please, enter \"x\" coordinate of a point: ");
  40.         double x = double.Parse(Console.ReadLine());
  41.  
  42.         Console.Write("Please, enter \"y\" coordinate of a point: ");
  43.         double y = double.Parse(Console.ReadLine());
  44.  
  45.         if ( Math.Pow(x-xo, 2) + Math.Pow(y-yo, 2) <= Math.Pow(R, 2) && ((x >= xMin || x <= xMax) && (y >= yMin || y <= yMax)) )
  46.         {
  47.             check = true;
  48.             Console.WriteLine("\n" + "Is the point with coordinates ({0};{1}) within the circle K(({2};{3}) {4}) and" + "\n"
  49.             + "out of the rectangle R(top={5}, left={6}, width={7}, height={8}): {9}", x, y, xo, yo, R, yMax, xMin, width, height, check);
  50.         }
  51.         else
  52.         {
  53.             check = false;
  54.             Console.WriteLine("\n" + "Is the point with coordinates ({0};{1}) within the circle K(({2};{3}) {4}) and" + "\n"
  55.             + "out of the rectangle R(top={5}, left={6}, width={7}, height={8}): {9}", x, y, xo, yo, R, yMax, xMin, width, height, check);
  56.         }
  57.         Console.WriteLine();
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment