stkirov

09.Point

Oct 12th, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. //Write an expression that checks for given point (x, y) if it is within the circle K( (1,1), 3) and out of
  2. //the rectangle R(top=1, left=-1, width=6, height=2).
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6.  
  7. class Program
  8. {
  9.     static void Main()
  10.     {
  11.         int x = 1;
  12.         int y = 4;
  13.         int absoluteX = Math.Abs(x - 1);
  14.         int absoluteY = Math.Abs(y - 1);
  15.         bool checkInCircle = Math.Sqrt((absoluteX * absoluteX) + (absoluteY * absoluteY)) <= 3; //3 is the radius
  16.         bool checkInRectangle = (x <= 5 && x >= -1 && y <= 1 && y >= -1);
  17.         if (checkInCircle && checkInRectangle)
  18.         {
  19.             Console.WriteLine("The point is in the cirlce and in the rectangle");
  20.         }
  21.         if (!checkInCircle && checkInRectangle)
  22.         {
  23.             Console.WriteLine("The point is not in the cirlce and in the rectangle");
  24.         }
  25.         if (checkInCircle && !checkInRectangle)
  26.         {
  27.             Console.WriteLine("The point is in the cirlce and not in the rectangle");
  28.         }
  29.         if (!checkInCircle && !checkInRectangle)
  30.         {
  31.             Console.WriteLine("The point is not in the cirlce and not in the rectangle");
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment