A segment can cross the viewing boundary
A vertex outside the viewing volume does not imply that the entire segment is invisible. The segment may enter the volume and leave through another plane. We can find exactly which part survives by intersecting parameter intervals, before dividing by the homogeneous coordinate. This note develops the line-segment case in exact arithmetic.
Use column clip coordinates and the symmetric convention
Other graphics APIs or depth conventions can use a different near-plane inequality. The method below applies to any explicitly specified collection of linear clip-space inequalities. This convention is the one used in the existing camera note, not a claim about every pipeline.
Definition 7.1.1
(Clipping a segment in clip space)
The input is a pair of clip coordinates , produced by the same linear transformation of the original endpoints, with their actual scales retained. The original affine parameter is , and
The six clipping functions are ; the clip volume is the set where all six are nonnegative. The output is the set , together with the clipped endpoints and when .
Changing the scale of one endpoint independently changes this parameterization. If an attribute was affine along the original segment, its value at a new endpoint must use this same original .
Each plane contributes an interval
Write the six inequalities as , with one of the six clipping functions. For one plane let and . Since is linear,
If both values are nonnegative, the entire current segment satisfies that plane. If both are negative, no point of the original segment satisfies it. Otherwise the boundary parameter is
When , keep ; when , keep . In either crossing case the denominator is nonzero. Initialize the retained interval to , intersect it with the allowed interval for every plane, and reject if its lower endpoint exceeds its upper endpoint. Equality leaves a single boundary point, whose handling as a drawable primitive requires a separate rendering convention.
Theorem 7.1.2
(Exactness of interval clipping)
For each of the six clipping functions , let , with , . Then:
- if and ;
- if and ;
- if , and if , where .
Consequently the set of parameters of points inside the clip volume is , which is a closed interval (the maximum of the lower bounds and the minimum of the upper bounds) or empty.
Proof
(Each plane gives a closed interval; the volume is their intersection)
The function is affine in .
If , then on . If , then is a convex combination of two negative numbers, hence negative, so .
If , then , so is strictly increasing and vanishes at exactly one point . Here because , and because is equivalent to . Strict monotonicity gives , so . If , then is strictly decreasing, , and , so .
A point is in the clip volume exactly when all six inequalities hold, that is, when lies in all six sets . Each is a closed interval or empty, and an intersection of closed intervals is a closed interval or empty. Its lower end is the maximum of the lower ends and its upper end the minimum of the upper ends.
Proof X-ray
Where each hypothesis enters the interval argument
The key move is to trade one geometric question, which part of a segment lies in a polyhedron, for six one-variable sign questions. That trade is legitimate only because is affine. Two hypotheses carry this. First, is affine in because the endpoints are the clip coordinates with their actual scales kept; rescaling one endpoint changes the curve being clipped. Second, every clipping function is linear in , so a composition with stays affine. An affine function of one variable is monotone, which is why its sign changes at most once and its nonnegative set is a single interval.
The argument closes because the retained sets are closed and are intersected, never united: a point is inside only if it passes every plane. The non-strict inequality is what makes each set closed, so the lower and upper bounds belong to the interval. If the inequalities were strict, the same proof would give half-open intervals and a boundary point would be dropped.
The argument would fail for a nonlinear condition. After perspective division the conditions are no longer affine in , and the counterexample below shows what goes wrong.
A crossing with unequal homogeneous coordinates
Worked example 7.1.3
(Entering through the left plane when w changes)
Take and . For the left plane , the endpoint values are and . The segment enters at . At this parameter,
The other five inequalities hold throughout : equals at and at , while and equal . So the retained interval is . If a scalar attribute is affine on the original segment with endpoint values and , its value at the new endpoint is .
Counterexample mode
Dividing first and then reusing the same parameter
A tempting claim: project both endpoints first, then interpolate the screen coordinate with the same . For the segment above, the screen coordinates are and . At this recipe gives . But the true clip-space point at is , whose screen coordinate is , exactly on the left boundary. Since , the recipe puts the new endpoint in the wrong place.
Perspective division is not an affine operation in the original parameter when changes. Clip the homogeneous segment first. After projection, use perspective-correct interpolation for attributes specified to vary affinely in the original surface parameter. Flat or screen-linear attributes follow their own declared interpolation rules.
Concept lensAlgebraic
The screen parameter is a fractional-linear function of t
Along the segment, the screen point has parameter , the share of the projected segment already traveled, where . Equal steps in are therefore unequal on the screen unless . For , , gives , and the screen coordinate lies on the left boundary, as the clip-space calculation found. Reusing as is what the counterexample refutes.
Worked example 7.1.4
(Both endpoints outside, but part of the segment visible)
Take and , so throughout. Both endpoints violate a plane, yet the middle of the segment is inside. For : , , so and the allowed set is . For : , , so and the allowed set is . The four planes in and give and impose nothing.
The retained interval is , with clipped endpoints and . An attribute that is affine along the original segment with end values and takes the values and there.
Worked example 7.1.5
(Rejection by an empty intersection)
Take and . Plane by plane: has , , so and the allowed set is . Plane has , , so and the allowed set is . The remaining four functions are nonnegative at both endpoints: takes the values and , takes and , and .
The intersection is empty, so the segment is rejected. The check is exact: at (that is, ) the point has , so the segment passes outside the corner of the square. Note that no single plane had both endpoints negative; the empty intersection is what detects the miss.
Boundary and representation checks
A plane through an endpoint is not a reason to divide by zero in the crossing formula: use the sign cases first. If both plane values are zero, the entire segment lies on that plane. If one is zero and the other negative, the intersection with that half-space may be only the endpoint. If the current lower bound exceeds the upper bound after combining planes, reject even if no single original endpoint violates every plane.
The six inequalities imply . At they also force , the zero homogeneous vector, which has no projective image. A retained zero vector must not be divided by ; a real pipeline needs a convention for such degenerate input or a suitable clipping domain ensuring positive . Simply discarding a whole segment because one retained endpoint is singular can also discard other points. Numerical tolerances, finite precision and tie rules must be specified separately from this exact derivation.
Common mistake
(Endpoints failing different planes do not decide the segment)
It is correct to reject a segment when both endpoints are negative for the same plane. The converse is false: in the rejection example the endpoints fail different planes ( fails , fails ) and no plane has both negative, yet the segment misses the volume. Conversely, endpoints that each violate some plane do not force rejection, as the segment from to shows. Only the intersection of the six intervals decides.
Common mistake
(Restarting the parameter after a first clip)
If planes are applied one after another, the second clip is computed on the shortened segment from to , with a new parameter . An attribute is still interpolated by the original parameter, which is ; using directly gives the wrong value. In the first example, after clipping to , the point of the shortened segment is , so the attribute is , not .
Exercises and solutions
Quick check
(For one plane, and . Find the retained interval.)
Decide which endpoint is on the allowed side.
Solution · Answer
Here , so and the retained interval is .
Quick check
(If , can any segment point pass that plane?)
Write in terms of and .
Solution · Answer
No. The affine value equals for every , so the allowed set is empty.
Quick check
(In the first worked example, use endpoint attribute values and . Find the attribute at the new endpoint.)
Use the original parameter .
Solution · Answer
.
Quick check
(If the lower and upper retained bounds both equal , is the mathematical intersection empty?)
Compare with the case where the lower bound exceeds the upper bound.
Solution · Answer
No; it consists of one boundary point. Whether it draws a sample is a separate convention.
For the underlying clip-space pipeline and its API-specific details, see Khronos, OpenGL 4.6 Core Profile specification, Section 13.7. This note derives a deliberately stated symmetric-volume segment model; it does not imply every API uses the same depth convention.