Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Write an expression that checks for given point (x, y) if it is within the circle K({1, 1}, 1.5) and out of the rectangle R(top=1, left=-1, width=6, height=2).
- namespace _10.PointInsideCircleButOutsideOfRectangle
- {
- using System;
- public class PointInsideCircleButOutsideOfRectangle
- {
- private const double CenterX = 1d;
- private const double CenterY = 1d;
- private const double Radius = 1.5d;
- private const double PointXOnLeftTopAngle = -1d;
- private const double PointYOnLeftTopAngle = 1d;
- private const double WidthRect = 6d;
- private const double HeightRect = 2d;
- public static void Main(string[] args)
- {
- checked
- {
- Console.Write("Enter value to X of given point: ");
- double pointX = double.Parse(Console.ReadLine());
- Console.Write("Enter value to Y of given point: ");
- double pointY = double.Parse(Console.ReadLine());
- bool pointIsInsideCircle = CheckGivenPointIsInsideTheCircle(pointX, pointY);
- bool pointIsOutsideOfRectangle = CheckGivenPointIsOutsideOfTheRectangle(pointX, pointY);
- bool pointIsInsideCircleButIsOutsideRectangle = pointIsInsideCircle && pointIsOutsideOfRectangle;
- Console.WriteLine("Given point is Inside the Circle, but is Outside of the Rectangle: {0} !", pointIsInsideCircleButIsOutsideRectangle);
- }
- }
- private static bool CheckGivenPointIsOutsideOfTheRectangle(double pointX, double pointY)
- {
- bool isOutside = false;
- if (pointX < PointXOnLeftTopAngle || pointX > PointXOnLeftTopAngle + WidthRect)
- {
- isOutside = true;
- }
- else if (pointY < PointYOnLeftTopAngle - HeightRect || pointY > PointYOnLeftTopAngle)
- {
- isOutside = true;
- }
- return isOutside;
- }
- private static bool CheckGivenPointIsInsideTheCircle(double pointX, double pointY)
- {
- // Here will use Gauss circle equation: (x-a)^2 + (y-b)^2 <= r^2 :
- bool isInside = true;
- double squareDiffX = (pointX - CenterX) * (pointX - CenterX);
- double squareDiffY = (pointY - CenterY) * (pointY - CenterY);
- double sqrtResult = Math.Sqrt(squareDiffX + squareDiffY);
- if (sqrtResult > Radius)
- {
- isInside = false;
- }
- return isInside;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement