예제 #1
0
        public static void Main()
        {
            Console.Title = "Check a Point is within a circle and outside rectangle";
            Console.WriteLine("Settings by task definition:");
            Console.ForegroundColor = ConsoleColor.White;

            // creates circle
            Console.WriteLine("Circle coordinates K((1,1),3).");
            Circle circle = new Circle(radius: 1.5d, x: 1.0d, y: 1.0d);

            // creates rectangle
            Console.WriteLine("Rectangle coordinates LU(-1,1) and RB(5,-1).\n");
            Rectangle rectangle = new Rectangle(leftUpX: -1.0d, leftUpY: 1.0d, rightDownX: 5.0d, rightDownY: -1.0d);

            // creates 2D-Point
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Enter 2D-Point coordinates.");
            Point point = new Point(x: EnterData("X"), y: EnterData("Y"));

            // check point position against Circle
            bool checkAgainsCircle = (((point.X - circle.X) * (point.X - circle.X)) + ((point.Y - circle.Y) * (point.Y - circle.Y)))
                <= (circle.Radius * circle.Radius);

            // ccheck point position against Rectangle
            bool checkAgainstRectangle = (point.X < rectangle.LeftUp.X) || (point.X > rectangle.RightDown.X) ||
                (point.Y > rectangle.LeftUp.Y) || (point.Y < rectangle.RightDown.Y);
            bool result = checkAgainsCircle && checkAgainstRectangle;

            Console.WriteLine("2D-Point is within a circle and outside rectangle - {0}", result.ToString());
            Console.ReadKey();
        }
예제 #2
0
 public static void Main()
 {
     Console.Title = "Point within a circle?";
     Console.WriteLine("Circle coordinates are set as (0,0) with radius of 2 by definition.");
     Circle circle = new Circle(2);
     Console.WriteLine("Let set the coordinates of the point:");
     Point point = new Point
                       {
                           X = InputData("X"),
                           Y = InputData("Y")
                       };
     string result = (point.X * point.X) + (point.Y * point.Y) <= (circle.Radius * circle.Radius) ? "WITHIN" : "OUTSIDE";
     Console.WriteLine("Point with coordinates ({0},{1}) is {2} a given circle [(0,0),2].", point.X, point.Y, result);
     Console.ForegroundColor = ConsoleColor.White;
     Console.ReadKey();
 }