Hidden Surface Removal Algorithms

When drawing a 3D object, we need to draw only "visible" to viewer faces. There are a variety of algorithms to do that with different strong points.

Backface Culling

A simple way to remove hidden surfaces for convex bodies is to put away all "backfacing" polygons, as they are not seen by the viewer (see Fig.1). A polygon is "backfacing" if its normal N is facing away from the viewing direction V, i.e. if (NV) = cos(a) > 0.
Interactive polyhedra applet. Drag the mouse to rotate objects. Look at Interactive polyhedra and Semiconductor microstructures for more examples.

For the non-perspective projection we can direct V along e.g. the Z axis, therefore
    (NV) = (Nez ) = cos(a) = Nz .
The value cos(a) = Nz is used also to determine brightness of the face in the "headlight" mode.

The backface culling algorithm has a HUGE speed advantage if we can use it since the test is cheap and we expect at least half the polygons will be discarded. If objects are not convex, one need to do more work. Usually it is performed in conjunction with a more complete hidden surface algorithm.

See also The Portal Technique for Real-time 3D Engines mainly useful for indoor engines.

Painter's Algorithm (Z-Sorting)

Draw polygons as an oil painter might: the farthest one first. This algorithm is used e.g. in James Gosling's "MoleculeViewer" Java 1.1 applet.
To draw stellated polyhedron the combinations of the backface culling and z-sorting is used in this applet. The non-convex body is broken into convex rays. Then these convex parts are z-sorted with respect of there center of mass positions and are ploted the farthest one first.

Interactive fractal polyhedra are obtained by recursive z-sorted translations.

Grid ordering

gridperspective We draw an array of objects (i, j) successively so, that zi, j grows when i or j are changed. From Fig.2 it follows, that in this case an object cannot be covered by a new more distant in z object.

Fig.2a shows, that unfortunately this trick doesn't work for the perspective projection, therefore IMHO one need use z-sorting in this case.

Grid ordering and backface culling are used in 3D Fractal Mountains applets.

Z-Buffer Algorithm

In addition to framebuffer, we'll have a depth buffer (or z-buffer) where we save z values. It's universal and the most powerful method. All modern OS uncludes a 3D engine with z-buffer (OpenGL, DirectX...) but unfortunately I can't get it by Java1.1. IMHO C# can get advantage of Java if it includes 3D graphics.

Comments to the 3D controls. Rotations

Two rotations are used in all 3D applets. The first rotation on an angle j around the Y axis and the second one on an angle q around X axis
    R = M r ,
where the matrix M is


It is evident, that for two successive zoomings the total scaling factor is
    Scale1+2 = Scale1 * Scale2 .
For Scalei = exp(c Dxi) where c is a constant and Dxi is mouse displacement we get
    Scale1 * Scale2 = exp(c Dx1) * exp(c Dx2) = exp[c (Dx1 + Dx2)] = Scale1+2 .
E-notes     free sources.
updated 10 Oct 2001