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), 3) and out of the rectangle R(top=1, left=-1, width=6, height=2).
- */
- using System;
- class PointWithinCircleOutOfRectangle
- {
- static void Main()
- {
- double pointCoordinateX, pointCoordinateY;
- int circleCenterCoordinateX = 1;
- int circleCenterCoordinateY = 1;
- int circleRadius = 3;
- int rectangleLeftX = -1;
- int rectangleTopY = 1;
- int rectangleWidth = 6;
- int rectangleHeidht = 2;
- string checkResultCircle, checkResultRectangle;
- string error01 = "Invalid input! Please enter a number between " + double.MinValue + " and " + double.MaxValue + "\n";
- Console.WriteLine("Enter coordinates of the point which you want to check");
- /* get coordinates of the point */
- Console.Write("X: ");
- if (!(double.TryParse(Console.ReadLine(), out pointCoordinateX) && pointCoordinateX > double.MinValue && pointCoordinateX <= double.MaxValue))
- {
- Console.WriteLine(error01);
- Main();
- }
- Console.Write("Y: ");
- if (!(double.TryParse(Console.ReadLine(), out pointCoordinateY) && pointCoordinateY > double.MinValue && pointCoordinateY <= double.MaxValue))
- {
- Console.WriteLine(error01);
- Main();
- }
- /* point within circle */
- if (Math.Sqrt(Math.Pow((pointCoordinateX - circleCenterCoordinateX), 2) + Math.Pow((pointCoordinateY - circleCenterCoordinateY), 2)) <= circleRadius)
- {
- checkResultCircle = "inside";
- }
- else
- {
- checkResultCircle = "outside";
- }
- /* point within rectangle */
- if ((pointCoordinateX <= (rectangleLeftX + rectangleWidth) && pointCoordinateX >= rectangleLeftX) && (pointCoordinateY >= (rectangleTopY - rectangleHeidht) && pointCoordinateY <= rectangleTopY))
- {
- checkResultRectangle = "inside";
- }
- else
- {
- checkResultRectangle = "outside";
- }
- /* show result information */
- Console.Write("The point P({0},{1}) is within the circle K(({2},{3}),{4}) and outside the rectangle R(top = {5}, left = {6}, width = {7}, height = {8})? -> ", pointCoordinateX, pointCoordinateY, circleCenterCoordinateX, circleCenterCoordinateY, circleRadius, rectangleTopY, rectangleLeftX, rectangleWidth, rectangleHeidht);
- Console.WriteLine((checkResultCircle == "inside" && checkResultRectangle == "outside") ? "TRUE" : "FALSE");
- Console.WriteLine("The point P({0},{1}) is {2} the circle K(({3},{4}),{5}) and {6} the rectangle R(top = {7}, left = {8}, width = {9}, height = {10})\n", pointCoordinateX, pointCoordinateY, checkResultCircle, circleCenterCoordinateX, circleCenterCoordinateY, circleRadius, checkResultRectangle, rectangleTopY, rectangleLeftX, rectangleWidth, rectangleHeidht);
- Main();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment