Motivation
A triangle can cross the boundary of a camera's viewing region. Rejecting it because one vertex is outside removes visible geometry; accepting it unchanged can send a division by zero into the image. Clipping is the geometric operation between those extremes: retain exactly the part of the primitive inside the permitted region. The result need not be a triangle, so an implementation must preserve both polygon connectivity and the meaning of newly created vertex attributes.
The earlier geometry and rasterization notes established the coordinate transformations and perspective quotient. Here we turn those facts into a complete finite procedure. We keep position and attributes together while clipping, triangulate the retained convex polygon, decide boundary sample ownership consistently, and finally compare depths. This separation matters because a numerically plausible intersection with a wrongly interpolated texture coordinate still represents the wrong surface.
All proofs initially concern exact arithmetic and nondegenerate input. A real implementation must choose a numerical policy for near-boundary values, use consistent arithmetic on shared edges, and document depth ties. An arbitrary tolerance added independently to every inequality is not itself a watertightness proof. We will state which conclusions are geometric and which require additional implementation discipline.
Definitions
Definition 7.2.1
(Homogeneous half-spaces and carried data)
A clip position is . A clip half-space is , with fixed nonzero . The conventional symmetric volume uses , and . A vertex record contains its position, every attribute assumed affine before division, and optionally its barycentric coordinates relative to the original triangle.
These homogeneous inequalities describe a cone in four-dimensional coordinate space. In an ordinary perspective camera with a positive near distance, surviving finite geometry has positive , permitting perspective division. The six inequalities alone also admit the zero vector; it is not a projective point. Input must come from a valid nonzero geometric representation, not an arbitrary list of four zeros.
Definition 7.2.2
(Oriented polygon and image sample rule)
A convex polygon is represented by a cyclically ordered list of its vertices. Its edges connect consecutive vertices, including the last to the first. After clipping and division, image triangles use a consistent counterclockwise orientation. For a directed edge , let . A sample is inside a triangle when each edge value is positive, with zero values resolved by one consistent half-open boundary rule.
Convexity is essential for the simple single-list algorithm below. Clipping a nonconvex polygon can produce disconnected pieces, which cannot always be represented correctly by one ordinary polygon loop. A triangle is convex, and intersection with a half-space preserves convexity, so the intended input remains in the safe class throughout the procedure.
Theorem / proposition
Theorem 7.2.3
(One-plane convex polygon clipping)
Let a nondegenerate convex polygon have cyclic vertices , and clip it by . Here inside includes the boundary: . For each directed edge , output: if both endpoints are inside; the boundary intersection if only is inside; the intersection followed by if only is inside; nothing if both are outside. For a crossing edge the intersection parameter is
A boundary endpoint can coincide with the computed intersection. After deleting duplicate consecutive vertices and removing a repeated final copy of the first vertex, the output describes exactly the polygon's intersection with the half-space, possibly empty or lower dimensional.
Theorem 7.2.4
(Affine attributes survive clipping and retriangulation)
Suppose a scalar attribute is affine in the original triangle's barycentric coordinates. Carry those coordinates through every clip intersection using the same parameter as the position. Assigning the attribute from those carried coordinates yields the original surface attribute everywhere in the clipped polygon. Any nondegenerate triangulation of that polygon gives the same attribute after perspective-correct interpolation at a common image point with positive homogeneous denominator.
The second theorem does not make arbitrary vertex data smooth across different original triangles. It ensures that subdividing one original affine surface model does not change that model. Discontinuous material coordinates, face normals and categorical labels need their intended boundary or flat-shading convention; treating a discrete label as a linearly varying number is not justified.
Proof sketch or proof idea
Proof
(Boundary walk and the four edge cases)
On an edge, linearity gives . If the endpoints are strictly on opposite sides, its unique zero gives the displayed formula and lies strictly between zero and one. The same expression reaches a boundary endpoint when that endpoint has value zero. An edge wholly outside cannot enter the half-space because its half-space value is a convex combination of two negative values.
Traverse the polygon boundary in order. Inside portions retain their order. At an exit, the retained boundary leaves the original polygon along the clip plane and returns at the next entry; convexity ensures that the connecting boundary segment lies in the polygon and on the clip plane. These are precisely the boundary pieces of the intersection. The four cases construct those pieces in cyclic order. If no inside area remains, the output is empty, a point, or a segment; such a result should not be rasterized as a nondegenerate triangle. Repeat the argument while the retained polygon has two-dimensional affine span. If an intermediate result is lower dimensional, discard it for filled-surface rendering: subsequent intersection cannot restore area. This proves the filled-region procedure for all six half-spaces.
Proof
(Carried barycentric coordinates reproduce the surface)
For attributes, let the original vertex values be and original barycentric vectors be the three coordinate vectors. At every new vertex carry . Its entries still sum to one, and both its position and its attribute agree with the original affine model. Induction proves this after every clipping pass. Any affine interpolation inside a new triangle reproduces the same original , because both functions agree at that triangle's three vertices. Perspective division changes image parameters but not the underlying surface value; the quotient formula therefore recovers that same value irrespective of the chosen diagonal.
Proof X-ray
The invariant is a coordinate description of the original surface
Carried barycentric coordinates provide more information than the final color. They record exactly where each new vertex came from on the original triangle. Every clipping step preserves their sum and their agreement with position. Retriangulation can then change a computational decomposition without changing the represented surface. This invariant is also a useful debugging tool: an incorrect attribute at a clipped edge is exposed before a rendered texture makes the error harder to locate.
Worked examples
Worked example 7.2.5
(A triangle clipped into a quadrilateral)
Use constant and vertices , , . Clip by . Here and . Each crossing has parameter . The retained polygon can be listed as , preserving the original clockwise order. Before using a counterclockwise raster test, reverse the order or adjust the sign convention. A fan gives two triangles; accepting only the original inside vertices would incorrectly retain merely the edge .
Concept lensGeometric
Clipping as a cut of the barycentric triangle
Write a point of the original triangle as with and . By linearity, becomes , a half-plane cut of the -triangle, so clipping is a polygon cut in barycentric space and the surviving coordinates are the carried ones. In the quadrilateral example, and give , whose boundary meets the edges and at their midpoints.
Worked example 7.2.6
(A clip vertex needs the original edge parameter)
On an edge let , , and attribute values . The entering intersection has , so and . Its projected edge parameter is . Using this screen parameter to clip the attribute would give two rather than one. Applying perspective correction to the screen weights instead gives , confirming the carried value.
Worked example 7.2.7
(One diagonal sample, one owner)
Split the square with vertices along its rising diagonal. The sample lies on that diagonal, so its edge value is zero for both adjacent triangles. With upward image coordinates, accept a zero edge only when its vertical increment is positive, or when horizontal and directed left. The diagonal from to owns the sample; its reversal does not. Thus the consistently oriented pair covers the sample exactly once. A closed test on both would cover it twice, which matters for blending or sample counts even when opaque colors happen to agree.
A complete clipping procedure
For each clip plane, start a fresh output list and set to the final input vertex. Walk each input vertex as , apply the four cases, then set . Feed the resulting list into the next plane. Stop when it is empty or its affine dimension drops below two; this is a filled-surface procedure. This cyclic initialization is necessary: otherwise the closing edge is never tested. A polygon with fewer than three distinct noncollinear projected vertices contributes no filled triangle.
Fan triangulation of a retained convex polygon uses for . Discard any zero-area fan triangles before interpolation. The remaining interiors are disjoint and their union covers the polygon up to its boundary: every point except lies on a ray from meeting one opposite boundary edge, placing it in the corresponding fan triangle. Internal diagonals need the same half-open ownership rule as original mesh edges. Do not give a boundary bias to the barycentric values used for interpolation; a coverage tie-break and an attribute formula serve different purposes.
For an image triangle with positive area denominator , the barycentric weights are edge values divided by . If its clip denominators are positive, a surface attribute is
Common mistake
(Perspective-correcting the divided depth)
Divided depth is affine in screen barycentric weights. Correcting it a second time is an error.
At each accepted opaque sample, retain the smallest valid depth. Induction over fragments proves that the buffer stores the minimum seen so far. Equal depths require a color tie rule, and a finite buffer requires a rounding convention; neither issue disappears because the ideal minimum is order independent.
Clipping and visibility answer different questions. Clipping removes geometry outside the view. Depth testing removes hidden contributions inside it. Back-face culling removes faces according to orientation under a separate material and topology assumption. A thin double-sided sheet cannot be treated as a closed one-sided solid merely because it is triangulated.
Common mistakes
Counterexample mode
All vertices outside does not mean all geometry outside
The image-space triangle has all vertices outside the square , yet contains the origin and covers part of the square. Rejecting it merely because no original vertex is inside loses visible area. A sufficient safe trivial-rejection condition is that all vertices violate the same clip half-space; it is not necessary for a triangle to be entirely outside. Other outside triangles are reduced to empty by clipping. For a partially visible triangle, all vertices of the retained portion may be newly created intersections.
The convexity hypothesis of the clipping proposition cannot simply be dropped.
Counterexample mode
A U-shaped polygon breaks the single-list rule
Apply the four cases, keeping , to the nonconvex U-shaped polygon . The true intersection is two disjoint unit squares, and . Walking the edges gives the single loop , which joins the squares by a zero-width bridge along . Fanning it from produces the triangle , which contains the point although that point lies in the gap between the squares. The repair is to split a nonconvex input into convex pieces first, or to use a clipper that can output several loops.
Common mistake
(Enlarging every triangle by an )
Independent floating-point calculations of a shared intersection can differ by a small amount, especially if endpoints are processed in opposite order. The exact proof establishes the target, not a complete numerical implementation. Reusing shared geometry, applying a canonical edge evaluation, or using a documented fixed-point coverage scheme can enforce consistency. Simply enlarging every triangle by an risks overlaps and changes the surface being rendered.
Summary
Half-space clipping is a finite boundary construction with four edge cases. Carrying original barycentric coordinates makes position and affine attributes stay synchronized, and proves invariance under retriangulation. Half-open coverage gives shared samples one owner; opaque depth testing then chooses the nearest candidate at each sample. Each stage has its own invariant and its own numerical conditions.
Exercises
Quick check
(A segment has , positions and attributes . Find its exit vertex and attribute.)
Solution · Answer
The parameter is . Thus the exit is and the attribute is . Both use the same parameter; using the final coordinate value as an interpolation weight has no justification.
Quick check
(Clip the counterclockwise triangle by . List the resulting polygon in cyclic order and give a two-triangle decomposition.)
Solution · Answer
The crossings are and . A cyclic output is . Its fan triangles are and . Both are counterclockwise, with areas one and , giving the retained area .
Quick check
(A clipped vertex has original barycentric coordinates and original values . Compute its attribute. Explain why clipping another edge from this vertex must interpolate its barycentric vector as well as position.)
Solution · Answer
The value is . The barycentric vector identifies the same original affine model at every intermediate vertex. Interpolating it on a later clipping edge preserves the invariant, whereas inventing new weights relative only to the latest polygon may lose the correspondence to the original values.
Quick check
(At a covered sample depths are . Under strict less-than comparison, which fragments update an initial depth of one? What happens to the two tied colors if their input order is exchanged?)
Solution · Answer
The first depth updates, the second equal depth fails, and updates. Before the nearer fragment arrives, the first tied color wins, so exchanging the two tied fragments exchanges that intermediate color. The final nearer color is unchanged. Order independence of the minimum depth does not imply a unique color among exactly tied surfaces.