# Implicit Surfaces

Implicit functions are widely used in computer graphics. They have applications in ray-tracing and are also used to determine whether a point is inside or outside of an object. This is useful when trying to simulate physical objects that can't pass through each other. Implicit functions are also called implicit surfaces, contour surfaces, isosurfaces, blobbies, or metaballs. While most 3D applications use implicit functions internally, only a few allow you to experiment with the formulas directly. (One program that does is a freeware raytracer called Povray. Povray has a built-in isosurface command that allows you to enter in mathematical formulas.)

This page is a sample of some of the effects that are easy to achieve with implicit surfaces. The surfaces on this page were created in Mathematica using the ContourPlot3D function.

Click and drag the cursor over these 3D models to rotate them. Hold down shift, click, and drag the cursor to zoom in or out.

x² + y ² + z² - 1 = 0

The equation above finds all the points at a distance of 1 from the origin. If we can find a way to test which sets of x, y, and z coordinates make this true, and only show those points, it will graph a sphere. One way of doing this is called the "marching cubes" algorithm. It essentially tests each quadrant of the area we are working in to see if anything is there. If not, it goes on to the next one. If there is something there, it subdivides the quadrant into smaller cubes and tests each of those. The process is repeated on smaller and smaller scales until it reaches the accuracy we desire. The models on this page were created in this way.

x² + (y-1.5) ² + z² - .5 = 0

This second equation graphs a smaller sphere to the right of center. Multiply the two together, and subtract a small constant:

(x² + y² + z² - 1) × ( x² + (y-1.5) ² + z² - .5) - .015 = 0

and we get a surface shaped like both of them blobbed together. Any two implicit surfaces will blob together like this when multiplied.

Shapes can be distorted in other ways by replacing the variables. We already saw above that replacing y with (y - 1.5) moved it to the side. If we replace y with x + y × 3, a function is sheared with a gradient of 3 (as has been done to the equation for a rounded cube below). With other replacements, it is possible to make an object look inflated, stretched, squashed, pinched, or bent. Once we've found a replacement that has the effect we want, we can use it on any function for a similar effect.

x^6 + (x + 3 y)^6 + z^6 - 1

If we replace y with √(y² + z²) it creates a surface of revolution about the y axis. This allows us to easily create any shape that might be made on a potter's wheel or lathe.

.5 × sin(x) + √(y² + z²) - 1.5

If we add two functions instead of multiplying them, the result is a shape blended halfway between the two. If the second function is a texture, it can be used to make the other surface look more weathered or realistic. In real life we never see a perfect cube. The corners are always somewhat rounded and the surfaces are more or less uneven. These kinds of realistic effects are easy to acheive with implicit functions. The figure to the left is a blend of a rounded cube and the lathed form used above. It is weighted to look less like a cube by multiplying that expression by .01.

.5 × sin(x) + (y² + z²)^.5 - 1.5 +
.01 × (x^6 + y^6 + z^6 - 1)

This figure is a more complicated blend of shapes created by adding simple cosine functions. They are oriented at various angles in space to create icosahedral symmetry.

2 - (cos(x + T*y) + cos(x - T*y) + cos(y + T*z) + cos(y - T*z) + cos(z - T*x) + cos(z + T*x))

T is the golden ratio in this expression.

Taking the minimum of two functions creates their union. Notice that no blobbing effect happens here. This is called CSG—Constructive Solid Geometry—in the graphics community.

Min((x - 1)² + (y - 1)² + (z - 1)² , x^6 + y^6 + z^6 - 1)

Taking the maximum creates the intersection. Intersecting with the negative of a function allows us to use one of the functions to cut away part of the other one, subtracting instead of adding.

Max((x - 1)² + (y - 1)² + (z - 1)² , x^6 + y^6 + z^6 - 1)