Advertisement
Teodor92

PointCheker

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