Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class Program
- {
- static void Main(string[] args)
- {
- // Coordinates of a specified point
- double xCoordinate = -100;
- double yCoordinate = -100;
- // The following section checks if a point is in a circle
- double centreXcoordinate = 1;
- double centreYcoordinate = 1;
- double radius = 1.5;
- // The next two lines calculate the distence from the centre to each coordinate
- //Follow the link to read about the test whether a point is in a circle
- //http://math.stackexchange.com/questions/198764/how-to-know-if-a-point-is-inside-a-circle
- double xDistance = xCoordinate - centreXcoordinate;
- double yDistance = yCoordinate - centreYcoordinate;
- bool isInCircle = (xDistance * xDistance) + (yDistance * yDistance) <= (radius * radius);
- if (!isInCircle)
- {
- Console.WriteLine("No.");
- return;
- }
- // The following section checks if a point is in a rectangle
- double top = 1;
- double left = -1;
- double width = 6;
- double height = 2;
- double xMin = left;
- double xMax = left + width;
- double yMin = top - height;
- double yMax = top;
- // X Out Of Range
- bool isXOutRangleRectangle = ((xCoordinate < xMin) || (xCoordinate > xMax));
- // Y Out Of Range
- bool isYOutRangleRectangle = ((yCoordinate < yMin) || (yCoordinate > yMax));
- // Point outside of a rectangle
- bool isOutsideRectangle = isXOutRangleRectangle || isYOutRangleRectangle;
- if (isInCircle && isOutsideRectangle)
- {
- Console.WriteLine("Yes.");
- }
- else
- {
- Console.WriteLine("No.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement