Statementâ–¼
Given the coordinates of four points
Each point
A square is defined as having:
Four sides of equal positive length
Four right angles (90 degrees)
Constraints:
p1.length == p2.length == p3.length == p4.length == 2
−104≤ xi​, yi​ ≤104
Solution
To determine if four points in 2D space form a square, we utilize the fundamental geometric properties of a square. A square is characterized by having four equal sides and two equal diagonals. By calculating the distances between all pairs of points, we can classify these distances into side lengths and diagonal lengths to verify the conditions of a square.
The squared distance between two points,