Sub topic 10
Checking a Mesh with Euler's Formula
Prerequisites and the Euler characteristic
This chapter assumes you understand basic 3D coordinates, vectors, introductory cross and dot products, and simple Python code. You should also know that a polygon mesh contains vertices, edges, and faces.
Euler's formula is a counting rule for a mesh:
\[ V - E + F = 2 \]
Here, V is the number of vertices, E is the number of unique edges, and F is the number of faces. For a closed mesh shaped like a sphere, the result is 2. This result is called the Euler characteristic. It depends on the surface's topology, meaning its connection pattern rather than the exact positions of its vertices.
A cube has 8 vertices, 12 edges, and 6 faces:
\[ 8 - 12 + 6 = 2 \]
Moving a cube vertex changes its geometry, but it does not change these counts. Therefore, the result remains 2.
Deriving edges from faces
An indexed face set stores vertex positions once. Each face then stores indices into the vertex list. Edges can be derived from consecutive indices in each face.
The same edge appears in two neighboring faces, so use an undirected representation. Sorting the two endpoint indices makes (1, 5) and (5, 1) represent the same edge.
from collections import Counter
vertices = [
(0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0),
(0, 0, 1), (1, 0, 1), (1, 1, 1), (0, 1, 1),
]
faces = [
(0, 3, 2, 1),
(4, 5, 6, 7),
(0, 1, 5, 4),
(3, 7, 6, 2),
(0, 4, 7, 3),
(1, 2, 6, 5),
]
def edges_of(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
edges = edges_of(faces)
V = len(vertices)
E = len(edges)
F = len(faces)
print(f"V={V}, E={E}, F={F}")
print(f"Euler characteristic: {V - E + F}")The output is:
V=8, E=12, F=6
Euler characteristic: 2When the result is not 2
The value 2 applies to a closed, connected surface with sphere-like topology. A surface with a handle, such as a torus, has a different value:
\[ V - E + F = 2 - 2g \]
g is the genus, or number of handles.
| Surface | Genus `g` | Euler characteristic |
|---|---|---|
| Sphere-like surface | 0 | 2 |
| Torus-like surface | 1 | 0 |
| Two-handle surface | 2 | -2 |
A mesh with a boundary also needs care. A flat disk has an outer boundary, so it is not a closed surface. Its counts can still produce a meaningful Euler characteristic, but comparing the result directly with 2 would be incorrect.
Disconnected meshes add the Euler characteristics of their separate components. Non-manifold meshes can also produce counts, but the result is less useful as a validity check because their connections do not describe an ordinary surface.
A practical checking sequence
Use Euler's formula after these checks:
- Count unique undirected edges from face boundaries.
- Count boundary edges, which belong to only one face.
- Count non-manifold edges, which belong to more than two faces.
- Confirm that the mesh is connected if you expect one component.
- Compute
V - E + F. - Compare the result with the expected topology.
Exercise
A closed sphere-like mesh has 20 vertices and 30 edges. How many faces should it have if Euler's formula applies?
Show answer
Rearrange V - E + F = 2: F = 2 - V + E = 2 - 20 + 30 = 12 faces.