Given coordinates of four points in a plane, find if the four points form a square or not.
To check for square, we need to check for following.
a) All fours sides formed by points are the same.
b) The angle between any two sides is 90 degree. (This condition is required as Quadrilateral also has same sides.
c) Check both the diagonals have the same distance
The idea is to pick any point and calculate its distance from the rest of the points. Let the picked point be ‘p’. To form a square, the distance of two points must be the same from ‘p’, let this distance be d. The distance from one point must be different from that d and must be equal to √2 times d. Let this point with different distance be ‘q’.
The above condition is not good enough as the point with different distance can be on the other side. We also need to check that q is at the same distance from 2 other points and this distance is the same as d.
Below are the implementations of the above idea.
Check if four segments form a rectangle
This article is contributed by Anuj. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Find Four points such that they form a square whose sides are parallel to x and y axes
- Check if the given 2-D points form T-shape or not
- Forming triangles using points on a square
- Check if a number is perfect square without finding square root
- Find Square Root under Modulo p | Set 1 (When p is in form of 4*i + 3)
- Check whether triangle is valid or not if three points are given
- Check whether two points (x1, y1) and (x2, y2) lie on same side of a given line or not
- Program to check if three points are collinear
- Check whether four points make a parallelogram
- Check if two people starting from different points ever meet
- Check whether it is possible to join two points given on circle such that distance between them is k
- Program to check whether 4 points in a 3-D plane are Coplanar
- Check whether a straight line can be formed using N co-ordinate points
- Check if the square of a number is divisible by K or not
- Check if given number is perfect square