Advertisement
AnitaN

03.OperatorsExpressionsStatements/10.PointInsideCircleOutsid

Mar 20th, 2014
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. //Problem 10.   Point Inside a Circle & Outside of a Rectangle
  2. //Write an expression that checks for given point (x, y) if it is within the circle K({1, 1}, 1.5) and out of the rectangle R(top=1, left=-1, width=6, height=2).
  3.  
  4. using System;
  5.  
  6. class PointInsideCircleOutsideRectangle
  7. {
  8.     static void Main()
  9.     {
  10.         Console.WriteLine("Please enter a X for point P(x,y):");
  11.         double pointX = double.Parse(Console.ReadLine());
  12.         Console.WriteLine("Please enter a Y for point P(x,y):");
  13.         double pointY = double.Parse(Console.ReadLine());
  14.         double pointXcenterCircle = Math.Abs(pointX - 1);
  15.         double pointYcenterCircle = Math.Abs(pointY - 1);
  16.         bool inRectangle = false;
  17.         bool inCircle = false;
  18.  
  19.         if (Math.Sqrt((pointXcenterCircle) * (pointXcenterCircle) + (pointYcenterCircle) * (pointYcenterCircle)) <= 1.5)
  20.         {
  21.             inCircle = true;
  22.         }
  23.         if (pointX >= -1 && pointX <= 5 && pointY <= 1 && pointY >= -1)
  24.         {
  25.             inRectangle = true;
  26.         }
  27.         if (inCircle && !inRectangle)
  28.         {
  29.             Console.WriteLine("The point P({0},{1}) is in the circle K((1,1),1.5), but not in the rectangle R(1,-1,6,2).", pointX, pointY);
  30.         }
  31.         else if (inRectangle)
  32.         {
  33.             Console.WriteLine("The point P({0},{1}) is in the rectangle R(1,-1,6,2).", pointX, pointY);
  34.         }
  35.         else if (inCircle)
  36.         {
  37.             Console.WriteLine("The point P({0},{1}) is in the circle K((1,1),1.5).", pointX, pointY);
  38.         }
  39.         else if (inCircle && inRectangle)
  40.         {
  41.             Console.WriteLine("The point P({0},{1}) is in the circle K((1,1),1.5) and in the rectangle R(1,-1,6,2).", pointX, pointY);
  42.         }
  43.         else
  44.         {
  45.             Console.WriteLine("The point P({0},{1}) is NOT in the circle K((1,1),1.5) and NOT in the rectangle R(1,-1,6,2).", pointX, pointY);
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement