Problem 2671. Check if vertices form a rectangle
Given a set of 4 vertices defined by vectors X and Y, return true if the vertices form a rectangle and false otherwise.
X and Y are not necessarily in sorted order, but you may assume that X(i) is paired with Y(i).
Also, if computing distances in your solution (e.g. with pdist), it is recommended that you round to three decimal places.
Solution Stats
Problem Comments
-
5 Comments
Show
2 older comments
Jan Orwat
on 21 Nov 2014
Matt, Jon's example can 'kill' some approaches, that check for trapezoids. X=[-1 -0.5 0.5 1]; Y=[0 sqrt(3)/2 sqrt(3)/2 0]; can eliminate those solutions which check only for 3 unique distances between points. It would be beneficial, to try some trapezoids, as well as kites or rhombi. Anyway, great problem!
Matthew Eicholtz
on 22 Nov 2014
Ah yes, I agree. Test suite updated again.
Dyuman Joshi
on 12 Jul 2022
I don't know why there is a loop in the test cases when the rng is set to a particular value. randi will generate the same values again and again.
Doesn't make much sense.
Solution Comments
Show commentsProblem Recent Solvers19
Suggested Problems
-
Swap the first and last columns
21011 Solvers
-
625 Solvers
-
305 Solvers
-
647 Solvers
-
739 Solvers
More from this Author44
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!