Sub topic 4
Geometry versus topology: positions and connections
This chapter assumes you can read simple Python and know 3D coordinates and basic vectors. It also assumes you have seen how a mesh is built from vertices, edges and faces. Here we separate two kinds of information that every mesh carries and show why keeping them apart matters in practice.
Two questions a mesh answers
A polygon mesh answers two different questions.
- Where are the points? This is the mesh's geometry: the numeric positions of the vertices in space (and anything else measured from those positions, such as edge lengths, angles, areas and face normals).
- Which points are connected, and how? This is the mesh's topology: which vertices form each edge, which edges bound each face, and which faces touch each other. Topology contains no coordinates. It is only about connections.
A useful test is to ask what survives stretching. If you take a rubber cube and stretch it into a long box, every length and angle changes, so the geometry changed. Every vertex is still joined to the same neighbors, and every face still has the same corners, so the topology did not.
| Property | Geometry or topology |
|---|---|
| Vertex position (1, 0, 0) | Geometry |
| Length of an edge | Geometry |
| Angle between two edges | Geometry |
| Area of a face | Geometry |
| "Vertex 2 and vertex 5 are joined by an edge" | Topology |
| "Face 3 has four corners" | Topology |
| "Edge (0, 1) is shared by two faces" | Topology |
| Number of vertices, edges and faces | Topology |
Face normals sit on the boundary. They are computed from positions, so they are geometry. The order of the vertex indices in a face (the winding order) is stored with the faces, so it is part of the connectivity data. Together, the two determine which way a face points.
How the indexed face set keeps them apart
The indexed face set from the previous chapter separates the two kinds of data in its layout. The vertices list holds only geometry. The faces list holds only topology, because it contains integers and no coordinates.
import math
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 in range(len(face)):
a, b = face[i], face[(i + 1) % len(face)]
edges.add((min(a, b), max(a, b)))
return edges
def edge_lengths(vertices, faces):
"""Count edges by length, rounded to avoid floating-point noise."""
lengths = Counter(
round(math.dist(vertices[a], vertices[b]), 6)
for a, b in edges_of(faces)
)
return sorted(lengths.items())
def scale(vertices, sx, sy, sz):
return [(x * sx, y * sy, z * sz) for x, y, z in vertices]
box = scale(vertices, 3, 0.5, 1)
print(edge_lengths(vertices, faces)) # [(1.0, 12)]
print(edge_lengths(box, faces)) # [(0.5, 4), (1.0, 4), (3.0, 4)]
print(len(vertices), len(edges_of(faces)), len(faces)) # 8 12 6The scale function takes only the vertex list and returns a new vertex list. It never sees faces. The cube's twelve equal edges become three groups of four different lengths, so the geometry changed. The mesh still has 8 vertices, 12 edges and 6 faces, and each face still names the same corners. The topology is identical.
Any operation that only moves vertices leaves the topology alone. This includes translation, rotation, scaling, shearing, bending, and every deformation a rig or sculpting brush performs. This is why animation systems can store one set of faces and many sets of positions, one per pose.
Same positions, different topology
The reverse also happens. You can keep the vertex positions fixed and change the connections. The standard example is a flat square split into two triangles, which can be done along either diagonal.
def edges_of(faces):
edges = set()
for face in faces:
for i in range(len(face)):
a, b = face[i], face[(i + 1) % len(face)]
edges.add((min(a, b), max(a, b)))
return edges
square = [(0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0)]
tris_a = [(0, 1, 2), (0, 2, 3)] # diagonal from vertex 0 to vertex 2
tris_b = [(0, 1, 3), (1, 2, 3)] # diagonal from vertex 1 to vertex 3
edges_a = edges_of(tris_a)
edges_b = edges_of(tris_b)
print(len(edges_a), len(edges_b)) # 5 5
print(sorted(edges_a ^ edges_b)) # [(0, 2), (1, 3)]Both meshes use the same four positions. Both cover the same unit square, and both have counter-clockwise winding seen from +z. They are still different meshes. The first has an edge between vertices 0 and 2, and the second has one between vertices 1 and 3. The ^ operator gives the symmetric difference of the two edge sets, so it shows exactly the edges that exist in one mesh and not the other.
On a flat square this difference is invisible. On a bent quad, where the four points do not lie in one plane, the two diagonals produce two different surfaces. The topology then changes what the shape looks like, which is why triangulation choices matter later in the tutorial.
Operations sorted by what they change
Most modeling operations fall clearly on one side. Some touch both.
| Operation | Geometry changes | Topology changes |
|---|---|---|
| Move, rotate, scale | Yes | No |
| Bend or twist deformer | Yes | No |
| Delete a face | No (other vertices stay put) | Yes |
| Merge two vertices | Yes (one position is lost) | Yes |
| Split an edge in the middle | No (the shape is unchanged) | Yes |
| Extrude a face | Yes | Yes |
| Triangulate a quad | No (the surface is unchanged if planar) | Yes |
Splitting an edge at its midpoint is a good example of an operation that adds a vertex without changing the shape. It adds one vertex to the list and rewrites the faces on either side. The surface still sits in exactly the same place. Only the connections are different.
Topological equivalence
Two meshes are topologically equivalent when you can deform one into the other without cutting, tearing or gluing. A cube, a box, a rounded cube and a closed mesh shaped like a ball are all equivalent. Each is a single closed surface with no holes, and this is why the cube satisfies V − E + F = 2, which a later chapter uses as a check.
A donut-shaped mesh is not equivalent to a ball, because you cannot turn one into the other without tearing a hole. This is a topological difference, and no amount of moving vertices removes it. The number of holes through a surface, called its genus, is a property of the topology.
When topology is broken but geometry looks fine
The most common practical error is a mesh whose geometry looks right but whose topology is wrong. A file importer, a Boolean tool or a hand-built script can produce vertices that sit at the same position but are separate entries in the list. The surface looks continuous, but the faces do not share vertices, so the mesh has seams. Renderers draw it without complaint, while smoothing, subdivision and edge selection all behave as if the seam were a cut.
The fix is to weld (merge) vertices that share a position.
from collections import Counter
def weld(vertices, faces, decimals=6):
"""Merge vertices with equal rounded positions; remap face indices."""
index_of = {}
new_vertices = []
remap = []
for v in vertices:
key = tuple(round(c, decimals) for c in v)
if key not in index_of:
index_of[key] = len(new_vertices)
new_vertices.append(v)
remap.append(index_of[key])
new_faces = [tuple(remap[i] for i in f) for f in faces]
return new_vertices, new_faces
def edge_use(faces):
use = Counter()
for f in faces:
for i in range(len(f)):
a, b = f[i], f[(i + 1) % len(f)]
use[(min(a, b), max(a, b))] += 1
return use
# Two triangles that touch along a diagonal, but each has its own copies
# of the shared corners (vertices 3 and 4 duplicate vertices 0 and 2).
vertices = [(0, 0, 0), (1, 0, 0), (1, 1, 0),
(0, 0, 0), (1, 1, 0), (0, 1, 0)]
faces = [(0, 1, 2), (3, 4, 5)]
before = edge_use(faces)
print(len(vertices), sum(1 for n in before.values() if n == 1)) # 6 6
new_vertices, new_faces = weld(vertices, faces)
after = edge_use(new_faces)
print(len(new_vertices), sum(1 for n in after.values() if n == 1)) # 4 4
print(new_faces) # [(0, 1, 2), (0, 2, 3)]Before welding there are six vertices and every one of the six edges is used by exactly one face, so each is a boundary edge. After welding there are four vertices and the diagonal edge (0, 2) is used by two faces. Only the four outer edges are boundary edges. The positions did not move, but the topology now says the two triangles are neighbors.
Choosing which to change
When a mesh problem appears, decide first whether it is a geometry problem or a topology problem. This tells you which tool to use.
- If the shape is the wrong size, position or curvature, edit positions.
- If the surface has seams, holes, or odd shading across edges that should be smooth, look at the connections.
- If a simulation, subdivision or Boolean operation fails, suspect topology first. These algorithms depend on neighbors being correctly connected, and they usually don't care whether the positions are "nice".
Exercise
You have a cube mesh with 8 vertices and 6 quad faces. (a) You scale it by a factor of 2 along the x axis. (b) You then split one edge at its midpoint, which adds a vertex and rewrites the two faces that share the edge. For each step, say whether the geometry changed, whether the topology changed, and give the new vertex count.
Show answer
(a) The geometry changed: positions along x are doubled, so edge lengths and areas change. The topology did not change, because the faces are untouched. The vertex count stays 8. (b) The topology changed, because there is a new vertex and the two neighboring faces now have five corners each. The shape did not change, because the new vertex sits on the original edge. The vertex count is now 9.