Edge vector Created 2026-10-20 Updated 2026-11-05
For endpoints with position vectors in an affine Euclidean SPACE, the directed edge vector from to is . Reversing orientation changes its sign, while translating both endpoints leaves it unchanged.
For a triangle, . Its side lengths are the norms of the corresponding edge vectors, and dot products determine angles. Choosing an orientation is essential: an undirected edge alone specifies the pair of opposite vectors, rather than one of them. Edge differences also describe how a scalar or vector field changes across a mesh.
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 .
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]))
With exact real coordinates and exact equality in 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.
Apply the same translation to every vertex:
translate :: Point -> Polygon -> Polygon
translate (u,v) = map (\(x,y) -> (x+u,y+v))
Every edge vector is unchanged because the added displacement cancels on subtraction. Hence lengths, angles, orientation and shape are preserved.
For cyclically ordered planar vertices, let , with indices modulo . They describe a convex regular polygon exactly when and there is a single choice of sign for which every successive edge vector is obtained by a rotation through in that orientation. Necessity follows from equal sides and equal exterior angles. Conversely, the edge vectors have the form . Their sum is zero because the corresponding geometric series runs through the distinct roots of unity. Summing its partial series shows that the vertices are a translated and scaled copy of those roots, so they form a convex regular polygon. A larger turn such as can instead trace a star, which is why merely checking a constant turning angle is insufficient.
Figure 1.
Equal sides, equal turns and the fundamental turn distinguish an ordinary regular polygon
. Original constructions: a square satisfies the edge-rotation criterion; a nonsquare rhombus has unequal turns; a five-point star uses the wrong turn, instead of . Arrows indicate traversal direction. Details.