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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find Four points such that they form a square whose sides are parallel to x and y axes
- Check whether four points make a parallelogram
- Check if four segments form a rectangle
- Euler's Four Square Identity
- Lagrange's four square theorem
- Find the area of the shaded region formed by the intersection of four semicircles in a square
- Count of obtuse angles in a circle with 'k' equidistant points between 2 given points
- Find the point on X-axis from given N points having least Sum of Distances from all other points
- Check if the given 2-D points form T-shape or not
- Check if given four integers (or sides) make rectangle
- Number of Integral Points between Two Points
- Prime points (Points that split a number into two primes)
- Minimum number of points to be removed to get remaining points on one side of axis
- Ways to choose three points with distance between the most distant points <= L
- Steps required to visit M points in order on a circular ring of N points
- Check if a number is perfect square without finding square root
- Check if a number is a perfect square having all its digits as a perfect square
- Forming triangles using points on a square
- Find four elements that sum to a given value | Set 1 (n^3 solution)
- How to print maximum number of A's using given four keys