\chapter{Simplicial occlusion}

\textbf{NOTE:} I have stolen this chapter verbatim from a tugboat 
article I wrote.

Occlusion ordering in our system is performed by first orthogonally 
projecting the two simplices onto the viewing plane. If a point of 
overlap is detected, we sort them according to the inverse orthogonal 
projection of that point back onto each shape.

\section{Point versus point}

If the points are not coincident but their projections coincide, 
then they are ordered by depth. Otherwise, the test is
inconclusive.

\section{Point versus line segment}

This routine determines the occlusion relationship between a point 
and a line segment. It first expresses the line segment in terms of 
an affine basis, given by its origin and direction vector. The point 
is then projected orthogonally onto the line defined by the segment, 
producing a candidate projection. If the projection of the point onto 
the viewing plane---its \(xy\)-coordinates---is nearly 
identical to the projection of this candidate, the test proceeds; 
otherwise, the point 
and line segment are considered not to occlude each other. Next, the 
algorithm checks whether the projection lies within the bounds of the 
segment itself by comparing vector signs and computing a normalized 
coefficient. If the projection falls within the unit interval of the 
segment, the algorithm reduces the problem to comparing the depth of 
the point and its projection on the line. If these conditions fail, 
the test is inconclusive.\looseness-1

\section{Point versus triangle}

This routine compares the occlusion relationship between a point and 
a triangle. The point and the triangle are first projected orthogonally 
onto the viewing plane, where a cross-product test is applied to check 
whether the projected point lies inside the projected triangle. If this 
test fails, the point and triangle are considered not to occlude one 
another. If the point lies inside the projection, the algorithm then 
projects the point vertically onto the plane of the triangle. Using an 
affine basis for the triangle, the coordinates of the point 
with respect to the triangle are solved via Gauss--Jordan elimination. 
If the solution lies within the unit square---ensuring the 
projection is inside the triangle---the algorithm reduces the problem 
to a point-point 
occlusion comparison between the original point and its projection on the 
triangle. If any step fails to satisfy these conditions, the test is 
inconclusive.

\section{Line segment versus line segment}

This routine determines the occlusion relationship between two line 
segments. First, both segments are projected onto the viewing plane, 
and their direction vectors are computed. If the direction vectors are 
not parallel, the algorithm solves for parameters \(t\) and \(s\) in 
the affine equations of the two lines using Gauss--Jordan elimination. 
If both parameters lie within the unit interval, the intersection point 
of the two line segments is found, and the occlusion is reduced to a 
point-point comparison of the inverse orthogonal projection of that 
point onto both original line segments.\looseness-1

If the direction vectors are parallel, the algorithm instead falls back 
to point-line segment tests: each endpoint of one segment is compared 
against the 
other segment using the point-line segment occlusion procedure. If any 
endpoint 
is found to occlude, the segments are ordered accordingly. If no 
consistent ordering can be determined, the test is inconclusive.

\section{Line segment versus triangle}

This routine compares the occlusion relationship between a line segment 
and a triangle. The algorithm begins by testing each endpoint of the 
segment against the triangle using the point-triangle occlusion 
procedure. It then tests the segment itself against each of the 
triangle's edges using the line-segment occlusion procedure. If any of 
these comparisons establishes a definite ordering, that result is 
returned. If no consistent conclusion can be 
drawn from the endpoint and edge tests, the test is
inconclusive.

\section{Triangle versus triangle}

This routine compares the occlusion relationship between two triangles. 
The algorithm first tests each edge of the first triangle against the 
second using the line-segment--triangle occlusion procedure. If any edge 
establishes a definite ordering, that result is 
immediately returned. If these edge tests are inconclusive, the 
algorithm proceeds by testing the vertices of the first triangle against 
the second, and the vertices of the second triangle against the first, 
using the point-triangle occlusion procedure. If any of these vertex 
tests determines a clear ordering, that result is returned. If neither 
the edge nor the vertex tests establish a consistent relationship, the 
routine concludes that the occlusion status is inconclusive.