3
A regular polygon is a polygon that is equiangular (all angles are equal in measure) and equilateral (all sides have the same length).
Your job is to find out if a given polygon is regular or not.
Specs
- You will be given a list of Cartesian coordinate 2-tuples which describe the polygon's vertices.
- The points will always make a valid polygon.
- You have to return a truthy / falsey for whether or not the polygon is regular.
- Assume vertices are rounded to the nearest int.
- They might or might not be in order.
- This is code-golf so shortest code in bytes wins!
Test Cases
Most test cases generated by this site.
[(1,2), (3, 2), (1, 0), (3, 0)] -> True
[(1, 1), (5, 3), (7, 7), (3, 5)] -> False
[(550,450), (455,519), (491,631), (609,631), (645,519)] -> True
[(106,81), (94,81), (84,88), (80,100), (84,112), (94,119), (106,119), (116,112), (120,100), (116,88)] -> True
Are the coordinates always integers? – Reto Koradi – 2015-12-07T03:59:54.883
Another question: Based on the examples, it looks like the vertices are not necessarily in order? – Reto Koradi – 2015-12-07T04:09:05.993
Surely a polygon with all integer coordinates cannot be regular unless it's a square? Are we assuming some rounding? – xnor – 2015-12-07T04:28:31.220
@xnor sorry forgot to mention, you're rounding to nearest int. – Maltysen – 2015-12-07T04:32:58.940
@RetoKoradi correct. they are in any order, updated question. – Maltysen – 2015-12-07T04:33:44.683
Are we allowed to take input as a list of complex numbers? – lirtosiast – 2015-12-07T04:35:13.047
@ThomasKwa no, but the actual list of pairs can be varied in format – Maltysen – 2015-12-07T04:35:51.957
I think
(0,0),(0,1),(2,1)
->True
is a good test case. – lirtosiast – 2015-12-07T05:06:05.977This question is unclear. How are we supposed to tell if the polygon is regular without knowing its exact coordinates? – feersum – 2015-12-07T06:06:24.907