Write a program to find if the given points form a rectangle. Points are given in anti clock wise direction starting from bottom left point.
Input (Point, Point, Point, Point) | Output (boolean) |
---|---|
[5, 2], [10, 2], [10, 5], [5, 5] |
true |
[-2, -2], [2, -2], [2, 0], [-2, 0] |
true |
[0, 0], [5, 0], [5, 5], [0, 5] |
true |
[-4, 0], [0, -5], [4, 0], [0, 5] |
false |
[2, 1], [8, 1], [9, 8], [6, 6] |
false |
class IsARectangle
{ public static void main(String s[])
{
Point firstPoint = new Point(5, 2);
Point secondPoint = new Point(10, 2);
Point thirdPoint = new Point(10, 5);
Point fourthPoint = new Point(5, 5);
System.out.println("Is a rectangle : " + isARectangle(firstPoint, secondPoint, thirdPoint, fourthPoint));
}
public static boolean isARectangle(Point firstPoint, Point secondPoint, Point thirdPoint, Point fourthPoint) {
//Write code here to find if the given points form a rectangle.
}
//If required write any additional methods here
//If required write any additional methods here
}
class Point {
double x;
double y;
Point(double x, double y) {
this.x = x;
this.y = y;
}
}