So far in the series, we’ve defined the basic idea that UGFs generalize SDFs and examined that when representing shapes, UGFs offer design freedom in the shapes’ normal cones. In most of the examples, we’ve shown that this freedom helps recapitulate the kinds of edge treatments we see in engineering software like rolling-ball blends and chamfers. In this post, we’ll take a look at the clearance and midsurface fields that apply to SDFs and the two-body field that applies to all UGFs.
Use the slider to change viewing modes:
The clearance field, \(\ugf{A} + \ugf{B}\,\), the midsurface field, \(\ugf{A} - \ugf{B}\,\), and the two-body field: \(\twobody{\ugf{A}}{\ugf{B}} \equiv \frac{\ugf{A} - \ugf{B}}{\ugf{A} + \ugf{B}}\). The clearance and midsurface fields are overlaid to demonstrate their orthogonality.
Clearance and midsurface fields
There are few concepts to unpack. First, lets just get a feel for why the sum and difference perform as clearance and midsurface fields. Let’s use one-dimensional functions on a line to represent the section between opposing shapes.
$$ \ugf{A} $$ |
-2 | -1 | 0 | +1 | +2 | +3 | +4 | |
$$ \ugf{B} $$ |
+4 | +3 | +2 | +1 | 0 | -1 | -2 | |
$$ \ugf{A} + \ugf{B} $$ |
+2 | +2 | +2 | +2 | +2 | +2 | +2 | |
$$ \ugf{A} - \ugf{B} $$ |
-6 | -4 | -2 | 0 | +2 | +4 | +6 | |
$$ \twobody{\ugf{A}}{\ugf{B}} $$ |
-3 | -2 | -1 | 0 | +1 | +2 | +3 |
Clearly, the sum indicates the clearance. The difference is the midsurface field, but scaled by a factor of two. If one zooms out of the sum field to the far side of either shape, the sum also doubles up far from the midsurface, so we normalize by two in the Shadertoy above.
The two-body field, \(\twobody{\ugf{A}}{\ugf{B}} \equiv \frac{\ugf{A} - \ugf{B}}{\ugf{A} + \ugf{B}}\), clearly ranges in \([-1, 1]\) in the region not contained in either of the shapes, creating a predictable parametric space for modulation, interpolation, and remapping.
The clearance is orthogonal to the midsurface
In the visualization, the sum and difference fields are clearly orthogonal, but why? Algebraically, it works out trivially enough, recalling that UGFs have unit gradient magnitude by definition and that orthogonal vectors dot to zero:
\[\begin{aligned} \inner{(\grad\ugf{A} + \grad\ugf{B}\,)}{(\grad\ugf{A} - \grad\ugf{B}\,)} &= \\ \inner{\grad\ugf{A}\,}{(\grad\ugf{A}\; - \grad\ugf{B}\,)} + \inner{\grad\ugf{B}\,}{(\grad\ugf{A}\; - \grad\ugf{B}\,)} &= \\ \inner{\grad\ugf{A}}{\!\grad\ugf{A}}\; - \inner{\grad\ugf{A}}{\!\grad\ugf{B}}\; + \inner{\grad\ugf{B}}{\!\grad\ugf{A}}\; - \inner{\grad\ugf{B}}{\!\grad\ugf{B}} &= \\ 1 - \inner{\grad\ugf{A}}{\!\grad\ugf{B}} + \inner{\grad\ugf{A}}{\!\grad\ugf{B}}\; - 1 &= 0 \;. \end{aligned}\]However, those of us from the Tristan Needham school of analysis might prefer a more geometric explanation:
The key observation is that when \(\ugf{A}\,\) and \(\ugf{B}\,\) are UGFs, the sum and difference gradient vectors form the diagonals of a rhombus, and therefore, are orthogonal. Note that this rhombus is contained in the normal cone of the fields’ intersection (green).
The sum and difference fields, \(S = \ugf{A}\, + \ugf{B}\,\) and \(D = \ugf{A}\, - \ugf{B}\,\), produce an orthogonal basis and using the Sampson Norm, \(\sampson{F} \equiv \frac{F}{\norm{\grad{F}}}\), \(\sampson{S}\) and \(\sampson{D}\) form an orthonormal basis, which can be a useful way of approximating distance-to-curve and constructing edge treatments. Perhaps we’ll do a deeper dive on this topic in a future post, but here’s a teaser from some old twitter threads.
Applications of the two-body field
The two-body field can be a convenient alternative to SDFs for modulating other fields and interpolating shape. In engineering applications, it can be uniquely handy when mapping one a shape from Cartesian space into a new field-driven parametric space. For example, consider the toolpath geometry for the saddle surface below. Two pairs of side walls \(U\) and \(V\) form two two-body fields, which, when multiplied by a constant characteristic length, creates a \(UVW\) coordinate space along with the the distance to the midsurface of the reference geometry, \(W\).
If working with oriented open or nested shapes, several two-body fields map be combined into larger piecewise continuous maps.
Generalized conics
When observing the two-body field above, you might have noticed that the circles inside the blue circle aren’t concentric. Let’s simplify the situation down to the two-body field of two points:
Apollonian circles and conic sections. Only between two points to we see an Apollonian family of circles, but between a circle and a line, we see the full family of conic sections: ellipses occur near the circle, hyperbola occur near the line, and a parabola appears at \(\Xi = 0\). Observe that the two-body parameterization creates constant spacing along the horizontal axis containing the circle centers.
If these circles look familiar, they are members of the family (pencil) of Apollonian circles which sometimes appear in engineering applications. These circles are described by curves that are the constant ratio of distance to two circles, and indeed, the two-body field may be suitably reparameterized:
\[\frac{\df{A}-\df{B}}{\df{A}+\df{B}} = t \quad\iff\quad \frac{\df{A}}{\df{B}} = \frac{1+t}{1-t} \,.\]When working with SDFs, our two-body parameterization has the useful property that the fields are evenly spaced, which is useful for both engineering and aesthetic applications. (This reparameterization is a one-dimensional Cayley transform, which often appears in hyperbolic geometry.)
As noticed by Ponce and Santibáñez, ratios of distance fields generalize conics from points, circles, and planes to arbitrary shapes, and UGFs further generalize those results beyond distance fields.
Summary
The sum and difference fields represent clearance and interference when applied to SDFs. When applied to UGFs, the two-body field, the ratio of the sum and difference fields, is a straightforward approach to setting up mapping spaces in engineering applications. Mysteriously, notes of conformal mapping and complex analysis appear to present themselves, which can be useful when working on combined engineering and aesthetic challenges.