ellapt

3.9.InCircleOutRectangle

Dec 14th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. using System;
  2.  
  3. class InCircleOutRectangle
  4. {
  5. static void Main()
  6. {
  7. Console.WriteLine("Check 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).");
  8. Console.Write("Please, enter x-coordinate: ");
  9. string inputFloat = Console.ReadLine();
  10. float xAbs, yAbs; // absolute point coordinates
  11. float xCoord, yCoord; // point coordinates relative to the circle's center
  12. float xCenter = 1.0f; // coordinates of the circle center
  13. float yCenter = 1.0f; //
  14. float r = 3.0f; // radius of the circle
  15. bool xRightInput, yRightInput;
  16.  
  17. xRightInput=float.TryParse(inputFloat, out xAbs);
  18. Console.Write("Please, enter y-coordinate: ");
  19. inputFloat = Console.ReadLine();
  20. yRightInput=float.TryParse(inputFloat, out yAbs);
  21. if (xRightInput && yRightInput)
  22. {
  23. xCoord = xAbs - xCenter;
  24. yCoord = yAbs - yCenter;
  25. if (((xCoord * xCoord) + (yCoord * yCoord)) < r * r) // in circle ?
  26. {
  27. if (!((xAbs > -1.0f && xAbs < 5.0f ) && (yAbs > -1.0f && yAbs < 1.0f))) // yes, check the rectangle
  28. {
  29. Console.WriteLine("Success! The point ({0}, {1}) is within circle K and out of the rectangle R.", xAbs, yAbs);
  30. }
  31. else
  32. {
  33. Console.WriteLine("The point ({0}, {1}) is within circle K, but it is in the rectangle R too.", xAbs, yAbs);
  34. }
  35. }
  36. else
  37. {
  38. Console.WriteLine("The point ({0}, {1}) is NOT within circle K(0, 5) and could be in/out of the rectangle R.", xAbs, yAbs);
  39. }
  40. }
  41. else
  42. {
  43. Console.WriteLine("Not valid coordinates!");
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment