Advertisement
Guest User

in circle out of rectangle

a guest
Mar 14th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. /*
  8.  * Write an expression that checks for given point (x, y) if it is within the circle K({1, 1}, 1.5)
  9.  * and out of the rectangle R(top=1, left=-1, width=6, height=2)
  10.  */
  11.  
  12. class PointInCircleOutRectangle
  13. {
  14.     static void Main()
  15.     {
  16.         float circleRad = 1.5f;
  17.         int centerX = 1, centerY = 1;
  18.         float pointX = 0f, pointY = 0f;
  19.  
  20.         bool isInCircle;
  21.         bool isOutRect;
  22.  
  23.         Console.WriteLine("Provide point X coordinate:");
  24.         while (!float.TryParse(Console.ReadLine(), out pointX))
  25.         {
  26.             Console.WriteLine("Please, enter valid integer.");
  27.         }
  28.  
  29.         Console.WriteLine("\nProvide point Y coordinate:");
  30.         while (!float.TryParse(Console.ReadLine(), out pointY))
  31.         {
  32.             Console.WriteLine("Please, enter valid integer.");
  33.         }
  34.  
  35.         isInCircle = (Math.Pow((pointX - centerX), 2) + Math.Pow((pointY - centerY), 2)) <= Math.Pow(circleRad, 2);
  36.         isOutRect = !(((pointX <= 5)&&(pointX >= -1)) && ((pointY <= 1)&&(pointY >= -1 )));
  37.        
  38.         Console.WriteLine("\n {0}",(isInCircle && isOutRect));
  39.  
  40.         Console.WriteLine("\nPress any key to exit.");
  41.        
  42.         Console.ReadKey();
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement