Sub topic 2
Edges: Connecting Vertices
A mesh edge is a line segment connecting two vertices. In a polygon mesh, an edge records a relationship between vertices rather than adding a new point in space. The edge connects vertex 2 to vertex 5, for example, while the vertex list stores the coordinates of vertices 2 and 5.
This chapter assumes you know basic 3D coordinates, introductory vector cross and dot products, and simple Python.
An edge is a pair of vertex references
An edge can be represented by two vertex indices:
edge = (2, 5)This means “connect the vertex at index 2 to the vertex at index 5.” The edge's position comes from the coordinates stored in the vertex list.
vertices = [
(0, 0, 0), # 0
(1, 0, 0), # 1
(1, 1, 0), # 2
(0, 1, 0), # 3
]
edge = (2, 3)
start = vertices[edge[0]]
end = vertices[edge[1]]
print(start) # (1, 1, 0)
print(end) # (0, 1, 0)The edge itself has no separate coordinates in this representation. It gets its endpoints by looking up the referenced vertices.
Edges belong to faces
A face is defined by an ordered list of vertex indices. Each neighboring pair in that list forms an edge. The final vertex also connects back to the first vertex.
For example, the face (0, 1, 2, 3) contains these four edges:
(0, 1)(1, 2)(2, 3)(3, 0)
The edge (3, 0) closes the face. Without this final connection, the polygon would be an open chain instead of a surface boundary.
| Face | Edges derived from the face |
|---|---|
| `(0, 1, 2, 3)` | `(0, 1)`, `(1, 2)`, `(2, 3)`, `(3, 0)` |
Directed and undirected edges
A face stores its vertices in order, so its edges are initially directed. The face (0, 1, 2) contains directed edges (0, 1), (1, 2), and (2, 0).
For connectivity, however, an edge is usually treated as undirected. The edge (0, 1) is the same connection as (1, 0). A common storage technique is to put the smaller index first:
def canonical_edge(a, b):
return (min(a, b), max(a, b))
print(canonical_edge(5, 2)) # (2, 5)
print(canonical_edge(2, 5)) # (2, 5)This canonical form lets a program recognize shared edges reliably.
Deriving unique edges from faces
Many mesh formats store vertices and faces but derive the edge list when needed. The following function collects each unique undirected edge:
def edges_of(faces):
"""Return unique undirected edges implied by polygon faces."""
edges = set()
for face in faces:
for i, a in enumerate(face):
b = face[(i + 1) % len(face)]
edges.add((min(a, b), max(a, b)))
return edges
faces = [
(0, 1, 2, 3),
(0, 4, 5, 1),
]
print(sorted(edges_of(faces)))The edge (0, 1) appears in both faces, but the set stores it only once. Shared edges are how software discovers which faces touch each other. This relationship is part of the mesh's topology, the connectivity structure that remains even when vertex positions change.
Exercise
What unique undirected edges are produced by the faces (0, 1, 2) and (0, 2, 3)?
Show answer
(0, 1), (0, 2), (1, 2), and (2, 3), because (0, 2) is shared by both faces.