#46Square Marker Validation
A computer vision system detects the four corner points of an object or marker in an image. Due to the unordered detection process, the four points may be provided in any order. Given four 2D points, determine whether they form a valid square.
A valid square must have:
- Four sides of equal positive length.
- Two diagonals of equal length.
- The diagonal must be longer than the side.
- All four points must be distinct.
Return true if the detected points form a square; otherwise, return false.
Real-World Applications: Drone Landing Zone Detection; UI Grid Shape Validation; Image Processing Shape Recognition;
Examples
Example 1
Input: A = [2,2]
B = [4,2]
C = [4,4]
D = [2,4]
Output: true
Explanation: The four points form a square with side length 2. Its four sides are equal and its diagonals are also equal.
Example 2
Input: A = [1,1]
B = [4,2]
C = [3,5]
D = [0,4]
Output: true
Explanation: The four points form a rotated square. The points are not aligned with the horizontal or vertical axes, but all four sides have equal length and the diagonals are equal.
Example 3
Input: A = [-2,1]
B = [3,1]
C = [4,4]
D = [0,4]
Output: false
Explanation: The distances between the four points do not satisfy the required square properties, so the detected object is not a valid square.
Constraints
- A.length == B.length == C.length == D.length == 2
- -10^4 <= xi, yi <= 10^4
- The four points are given in any order.