Advertisement
sylviapsh

Is Point In Circle Out of Rectangle

Dec 28th, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2. class IsPointInCircleOutRectangle
  3. {
  4.   static void Main()
  5.   {
  6.     //Write an expression that checks for given point (x, y) if it is within the circle K( (1,1), 3) and out of the rectangle R(top=1, left=-1, width=6, height=2).
  7.  
  8.     Console.Write("Enter point's coordinate x:");
  9.     double pointCoordinateX = double.Parse(Console.ReadLine());
  10.     Console.Write("Enter point's coordinate y:");
  11.     double pointCoordinateY = double.Parse(Console.ReadLine());
  12.  
  13.     double circleCoordinateX = 1;
  14.     double circleCoordinateY = 1;
  15.     double circleRadius = 5;
  16.  
  17.     double rectangleTop = 1;
  18.     double rectangleLeft = -1;
  19.     double rectangleWidth = 6;
  20.     double rectangleHeight = 2;
  21.  
  22.     bool isInCircle = (((pointCoordinateX - circleCoordinateX) * (pointCoordinateX - circleCoordinateX) + ((pointCoordinateY - circleCoordinateY) * (pointCoordinateY - circleCoordinateY))) <= circleRadius * circleRadius);
  23.     bool isOutRectangle = ((pointCoordinateX < rectangleLeft) || (pointCoordinateX > (rectangleWidth + rectangleLeft)) || (pointCoordinateY > rectangleTop) || (pointCoordinateY < (rectangleTop - rectangleHeight)));
  24.     bool inCircleOutRectangle = isInCircle && isOutRectangle;
  25.  
  26.     Console.WriteLine("The point ({0}, {1}) {2} inside the circle and outside the rectangle!", pointCoordinateX, pointCoordinateY, inCircleOutRectangle ? "is" : "isn't");
  27.   }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement