Equal side lengths alone are insufficient: a nonsquare rhombus is not a regular polygon. Use the regular polygon edge rotation criterion: for , successive nonzero edge vectors must be related by the same rotation through either or .With exact real coordinates and exact equality in
regular :: Polygon -> Bool
regular ps
| length ps < 3 = False
| otherwise = norm2 (head es) > 0 && (fits 1 || fits (-1))
where
es = [ (u-x,v-y) | ((x,y),(u,v)) <- edges ps ]
angle = 2*pi / fromIntegral (length ps)
norm2 (x,y) = x*x+y*y
close x y = abs (x-y) <= 1e-10 * max 1 (max (abs x) (abs y))
same (x,y) (u,v) = close x u && close y v
turn s (x,y) = (cos angle*x - s*sin angle*y,
s*sin angle*x + cos angle*y)
fits s = and (zipWith (\a b -> same (turn s a) b)
es (tail es ++ [head es]))same, this is an if-and-only-if test for an ordinary convex regular polygon, in either boundary orientation. The displayed Double implementation tests that condition to the stated tolerance; it cannot promise exact geometric classification near the tolerance boundary. Both orientations are needed, and using the fundamental turn excludes regular star traversals. A repeated zero-length side fails the exact criterion. Articles by others on the same topic
There are currently no matching articles.