Sub topic 3
Faces: surfaces bounded by edges
This chapter assumes you know 3D coordinates, the cross product, and basic Python. The earlier chapters introduced vertices as points and edges as segments joining two vertices. A face is what those edges enclose. This chapter covers what a face is, how it is stored, which conditions make it valid, and how to measure it.
What a face is
A face is a flat polygon bounded by a closed loop of edges. The loop gives the face its shape. The interior is the patch of surface inside the loop.
A face is defined by an ordered list of vertices. Each consecutive pair in the list forms an edge, and the last vertex connects back to the first. A face with n vertices has n edges. The number of vertices is the face's degree, or valence. Degree 3 is a triangle and degree 4 is a quad. Larger degrees are n-gons, which a later chapter covers.
A face stores no surface of its own. It is a rule that says "the region enclosed by these vertices, in this order." The surface itself is implied by the vertex positions.
A face as an index loop
The cube from the topology chapters stores each face as a tuple of vertex indices. The code below recovers a face's edges in order. It also measures the face using only its vertex positions.
import math
vertices = [
(0, 0, 0), # 0
(1, 0, 0), # 1
(1, 1, 0), # 2
(0, 1, 0), # 3
(0, 0, 1), # 4
(1, 0, 1), # 5
(1, 1, 1), # 6
(0, 1, 1), # 7
]
faces = [
(0, 3, 2, 1), # bottom
(4, 5, 6, 7), # top
(0, 1, 5, 4), # front
(3, 7, 6, 2), # back
(0, 4, 7, 3), # left
(1, 2, 6, 5), # right
]
def face_edges(face):
"""Directed edges around a face, in loop order."""
return [(face[i], face[(i + 1) % len(face)]) for i in range(len(face))]
def newell_vector(verts, face):
"""Newell's method: a vector along the face normal whose length is 2 * area."""
nx = ny = nz = 0.0
for a, b in face_edges(face):
x1, y1, z1 = verts[a]
x2, y2, z2 = verts[b]
nx += (y1 - y2) * (z1 + z2)
ny += (z1 - z2) * (x1 + x2)
nz += (x1 - x2) * (y1 + y2)
return (nx, ny, nz)
def face_area(verts, face):
n = newell_vector(verts, face)
return 0.5 * math.sqrt(sum(c * c for c in n))
def max_offset_from_plane(verts, face):
"""Largest distance of any face vertex from the plane through the first vertex."""
n = newell_vector(verts, face)
length = math.sqrt(sum(c * c for c in n))
if length == 0:
raise ValueError("degenerate face: zero area")
unit = tuple(c / length for c in n)
p0 = verts[face[0]]
return max(
abs(sum(u * (p - q) for u, p, q in zip(unit, verts[i], p0)))
for i in face
)
print(face_edges(faces[1])) # [(4, 5), (5, 6), (6, 7), (7, 4)]
print(face_area(vertices, faces[1])) # 1.0
print(max_offset_from_plane(vertices, faces[1])) # 0.0
bent = [(0, 0, 0), (1, 0, 0), (1, 1, 0.5), (0, 1, 0)]
print(round(max_offset_from_plane(bent, (0, 1, 2, 3)), 4)) # 0.2357The first call lists the four edges of the top face. The (7, 4) entry is the wrap-around edge that closes the loop. The second call gives the top face an area of 1, which matches a unit square. The third call shows the top face is perfectly flat.
The bent quad has one corner lifted by 0.5. Its fourth vertex sits 0.2357 units off the plane of the others, so it is not a valid flat face.
Where Newell's method comes from
Taking one cross product of two edges works for a triangle. For a quad or n-gon it depends on which three vertices you pick. If those vertices form a nearly straight line, or a reflex corner in a concave polygon, the result is noisy or has the wrong sign.
Newell's method sums a small contribution from every edge. It uses all vertices, so it gives a stable normal for any simple polygon, convex or concave. It also gives the area for free, because the vector's length is twice the polygon's area. For a non-planar polygon it returns a best-fit normal, which is why the planarity check above compares each vertex against it.
What makes a face valid
Every face in a clean mesh meets the conditions in this table.
| Property | Requirement | What goes wrong if violated |
|---|---|---|
| Vertex count | At least 3 | One or two vertices enclose no area. |
| Distinct vertices | No index appears twice in the loop | The loop pinches into a bow-tie or collapses an edge to zero length. |
| Non-zero area | Vertices are not all collinear | The normal is undefined and shading breaks. |
| Planar | All vertices lie on one plane | Renderers split the face into triangles, and the split changes the shape. |
| Simple loop | Edges do not cross each other | The interior and orientation become ambiguous. |
| No holes | One boundary loop only | A ring shape cannot be stored as a single face. |
A face that has a zero-length edge, or zero area, is called degenerate. Degenerate faces are common after careless merging of vertices, and many tools can find and remove them.
Planarity is a promise
Triangles are always planar, because three points define a plane. A quad has four points, so a fourth vertex can sit off the plane of the other three. Nothing in the indexed face set prevents this. The data structure stores a loop of indices and cannot tell whether the points are coplanar.
A non-planar quad is ambiguous. It can be split into two triangles along either diagonal. The two splits give different surfaces, and one is a valley where the other is a ridge. The pipeline must choose a diagonal, and the model may look different depending on the choice.
Concave faces and holes
A face may be concave, meaning one or more interior angles exceed 180 degrees. An L-shaped polygon is an example. The face is still valid as long as its edges do not cross. Concave faces are harder to triangulate and shade, so many tools prefer convex faces.
A face with a hole, such as a flat washer, has two boundary loops. A basic indexed face set stores only one loop per face. To model a washer, split it into several faces around the ring, or bridge the inner loop to the outer loop with a pair of coincident edges. The split version is cleaner, because it keeps every face a simple polygon.
Faces and the edges they share
Each edge of a face is shared with at most one other face in a well-formed surface. In the cube, the edge between vertices 4 and 5 belongs to the top face and the front face. This sharing is what makes a collection of polygons a connected surface rather than a pile of separate shapes.
The count of faces per edge decides what kind of surface you have:
- An edge used by one face lies on the boundary of the surface.
- An edge used by exactly two faces is an interior edge.
- An edge used by three or more faces is a non-manifold edge, which most tools treat as an error.
Later chapters build checks on this idea. At this point, remember that a face does not only own its edges. It borrows them from neighbors, and the sharing is what gives the mesh its connectivity.
The starting vertex and the direction
Two face tuples can describe the same polygon. The loop (4, 5, 6, 7) is the same face as (5, 6, 7, 4), because rotating the starting point changes neither the edges nor the direction. Reversing the order to (7, 6, 5, 4) gives the same region but a loop that runs the other way. The reversed loop flips which side counts as the front, which the winding order chapter covers in detail.
This matters when you compare faces. A set-based comparison of indices treats rotated and reversed loops as equal. Compare loops by the cyclic order if direction matters to your task.
Common mistakes
- Treating a face's vertex order as arbitrary. The order must trace the boundary, or edges will cross and you get a bow-tie.
- Repeating the first vertex at the end of the list, as some file formats do. The wrap-around edge is already implied, so the repeat produces a zero-length edge in code like
face_edges. - Assuming that a face with four vertices is a flat square. Check planarity.
- Dividing by the Newell vector's length without guarding against zero. A degenerate face makes this fail, as the function above shows.
- Forgetting that the edge wraps from the last vertex to the first. An off-by-one in that wrap drops one edge from every face.
Exercise
A triangle has vertices at (0, 0, 0), (2, 0, 0) and (0, 2, 0), listed in that order. What is face_edges((0, 1, 2)), and what area does Newell's method give? Describe how you get the area from the Newell vector.
Show answer
face_edges((0, 1, 2)) returns [(0, 1), (1, 2), (2, 0)], where the last pair is the wrap-around edge. Newell's method gives the vector (0, 0, 4), whose length is 4. The area is half that length, so 2, which matches the right triangle with legs of length 2 (½ × 2 × 2).
Exercise
A quad has vertices at (0, 0, 0), (1, 0, 0), (1, 1, 0.5) and (0, 1, 0). Why is it a problem for rendering, and what is the usual fix?
Show answer
Its fourth point lies off the plane of the others (about 0.2357 units from the plane in the chapter's check), so the quad is non-planar. A renderer must split it into two triangles, and the two possible diagonals give different surfaces. The usual fix is to move the vertex back onto the plane, or to replace the quad with two explicit triangles so the intended shape is stored.