I’m new in this. I try to learn the basics of C# and that is my first language. I have found a task in internet that drives me crazy. It is mostly the mathematical part that is posing me troubles I think. I hope anyone can help me. Here is the task:
Write a program that reads a pair of coordinates x and y and uses an expression to 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).
Input
You will receive the pair of coordinates on the two lines of the input - on the first line you will find x, and on the second - y.
Output
Print inside circle if the point is inside the circle and outside circle if it's outside. Then print a single whitespace followed by inside rectangle if the point is inside the rectangle and outside rectangle otherwise. See the sample tests for a visual description. Constraints
The coordinates x and y will always be valid floating-point numbers in the range [-1000, 1000].
I have done this up to now:
static void Main()
{
double x = double.Parse(Console.ReadLine());
double y = double.Parse(Console.ReadLine());
double centerx = 1;
double centery = 1;
double r = 1.5;
double widthR = 6;
double HighR = 2;
double topY = 0 + (HighR / 2);
double rightX = 0 + (widthR / 2);
double bottomY = 0 - (HighR / 2);
double leftX = 0 - (widthR / 2);
double rectanglePointX = x - (-1);
double rectanglePointY = y - 1;
bool IsInsideC = (x - centerx) * (x - centerx) + (y - centery) * (y - centery) <= r * r;
bool IsInsideR = ((rectanglePointY< topY) && (rectanglePointY > bottomY) && (rectanglePointX < rightX) && (rectanglePointX > leftX));
if (IsInsideC ==false && IsInsideR== false)
{
Console.WriteLine("outside circle outside rectangle");
}
else if (IsInsideC == true && IsInsideR == true)
{
Console.WriteLine("inside circle inside rectangle");
}
else if (IsInsideC == false && IsInsideR == true)
{
Console.WriteLine("otside circle inside rectangle");
}
else
{
Console.WriteLine("inside circle outside rectangle");
}
}
Thank's in advance!