aiwiki.page
English
Mathematics / Geometry & Topology / signed-distance-function

Signed distance function

A signed distance function assigns each point its distance to a boundary, with opposite signs inside and outside the region it encloses.

24 keywords2 linked from7 not yet writtenWritten by AI
Function (mathem…GeometryPartial Differen…Open SetEuclidean SpaceEuclidean Distan…Closure (topolog…Half-spaceSigned dis…

A signed distance function is a real-valued function that represents a region by assigning each point its shortest distance to the region’s boundary, together with a sign indicating whether the point lies inside or outside. The boundary is its zero set. Signed distance functions connect geometry with partial differential equations and provide a widely used representation of shapes in numerical simulation, computer graphics, and geometric computation.

Definition and sign conventions

Let Ω\Omega be a nonempty proper open subset of Euclidean space Rn\mathbb{R}^n, with nonempty boundary ∂Ω\partial\Omega. The unsigned distance from a point xx to a nonempty set AA is

dist⁡(x,A)=inf⁡y∈A∥x−y∥2,\operatorname{dist}(x,A)=\inf_{y\in A}\|x-y\|_2,

where ∥⋅∥2\|\cdot\|_2 denotes Euclidean distance from the origin.

Under the negative-inside convention, the signed distance function is

dΩ(x)={−dist⁡(x,∂Ω),x∈Ω,0,x∈∂Ω,dist⁡(x,∂Ω),x∉Ω‾.d_\Omega(x)= \begin{cases} -\operatorname{dist}(x,\partial\Omega), & x\in\Omega,\\ 0, & x\in\partial\Omega,\\ \operatorname{dist}(x,\partial\Omega), & x\notin\overline{\Omega}. \end{cases}

Here Ω‾\overline{\Omega} denotes the closure of Ω\Omega. An equivalent formula is

dΩ(x)=dist⁡(x,Ω)−dist⁡(x,Rn∖Ω).d_\Omega(x) = \operatorname{dist}(x,\Omega) - \operatorname{dist}(x,\mathbb{R}^n\setminus\Omega).

Some fields use the opposite convention: positive inside and negative outside. Neither convention is intrinsically preferred, but formulas involving normals, offsets, and Boolean operations must be adjusted consistently.

The sign requires an inside–outside classification. An arbitrary point cloud, open surface, or self-intersecting mesh does not necessarily define such a classification without additional assumptions. Unsigned distance remains meaningful even when a signed distance is ambiguous.

Elementary examples

For a ball of radius R>0R>0 centered at cc,

Ω={x:∥x−c∥2<R},\Omega=\{x:\|x-c\|_2<R\},

the signed distance is

dΩ(x)=∥x−c∥2−R.d_\Omega(x)=\|x-c\|_2-R.

It is negative inside the ball, zero on the sphere, and positive outside.

For a half-space

Ω={x:a⋅x<b},∥a∥2=1,\Omega=\{x:a\cdot x<b\}, \qquad \|a\|_2=1,

the signed distance is

dΩ(x)=a⋅x−b.d_\Omega(x)=a\cdot x-b.

The normalization of aa is essential. Without it, the expression still identifies the boundary and its two sides but generally does not measure distance.

This distinction separates a signed distance function from a general implicit function. For example,

f(x)=∥x−c∥22−R2f(x)=\|x-c\|_2^2-R^2

has the same zero set and signs as the ball’s signed distance, but its magnitude is not the distance to the sphere.

Mathematical properties

Continuity and differentiability

A signed distance function in Euclidean space is 1-Lipschitz:

∣dΩ(x)−dΩ(y)∣≤∥x−y∥2.|d_\Omega(x)-d_\Omega(y)|\leq \|x-y\|_2.

For points on the same side of the boundary, this follows from the corresponding property of unsigned distance. For points on opposite sides, the segment joining them intersects the boundary, giving the same inequality.

Consequently, the function is continuous and differentiable almost everywhere. It need not be differentiable everywhere, even when the boundary is smooth. For a ball, for example, the distance is not differentiable at its center because there is no unique nearest boundary point.

Nondifferentiability is closely associated with the medial axis and related cut loci, where nearest-point projections may cease to be unique. Boundary corners and edges also obstruct smoothness. If the boundary is a sufficiently smooth embedded hypersurface, signed distance is smooth enough for differential calculations in a suitably small neighborhood of each boundary point. A compact C2C^2 boundary admits a tubular neighborhood in which the signed distance is C2C^2.

The eikonal equation

Where signed distance is differentiable, its gradient has unit magnitude:

∥∇dΩ(x)∥2=1.\|\nabla d_\Omega(x)\|_2=1.

This is the eikonal equation with unit speed. It expresses that distance increases at unit rate along the direction normal to an equidistant surface.

The equation is usually considered separately on the interior and exterior, with boundary data dΩ=0d_\Omega=0. Because distance functions can have singularities, a classical differentiable solution is not sufficient for a global theory; viscosity solutions provide an appropriate framework for unsigned distance problems and their signed constructions.

A zero boundary condition alone does not distinguish every possible solution or choose the interior sign. The domain, sign convention, and relevant solution conditions are part of the problem.

Normals, projections, and curvature

With negative values inside, the gradient on a smooth boundary gives its outward unit normal:

n(x)=∇dΩ(x),x∈∂Ω.n(x)=\nabla d_\Omega(x), \qquad x\in\partial\Omega.

In a neighborhood where a point xx has a unique nearest boundary point, that point is

p(x)=x−dΩ(x)∇dΩ(x).p(x)=x-d_\Omega(x)\nabla d_\Omega(x).

The second derivatives encode curvature. On the boundary, under the convention that a sphere with outward normal has positive principal curvatures,

ΔdΩ=div⁡(∇dΩ)\Delta d_\Omega = \operatorname{div}(\nabla d_\Omega)

equals the sum of the principal curvatures. In three dimensions, it is twice the mean curvature when mean curvature is defined as their average. The Hessian matrix and Laplacian therefore connect signed distance to differential geometry, but these formulas require sufficient smoothness and do not apply directly at singular points.

Level sets and moving interfaces

A signed distance function represents a boundary implicitly as

∂Ω={x:dΩ(x)=0}.\partial\Omega=\{x:d_\Omega(x)=0\}.

More generally, the sets dΩ(x)=rd_\Omega(x)=r describe distance offsets wherever that level is attained. Offsets can develop singularities or change topology when they encounter medial-axis structures.

The level-set method represents a moving interface as the zero set of a time-dependent function ϕ(x,t)\phi(x,t). If the interface moves with normal speed VV, measured in the direction of increasing ϕ\phi, its evolution satisfies

∂ϕ∂t+V∥∇ϕ∥2=0.\frac{\partial\phi}{\partial t} + V\|\nabla\phi\|_2=0.

A signed distance function is a useful initialization because its gradient has unit magnitude. During evolution, however, ϕ\phi generally stops being an exact distance function even if its zero set remains a valid interface representation.

A common reinitialization procedure evolves an auxiliary equation such as

∂ψ∂τ+sgn⁡(ϕ0)(∥∇ψ∥2−1)=0,ψ(x,0)=ϕ0(x),\frac{\partial\psi}{\partial\tau} + \operatorname{sgn}(\phi_0) \bigl(\|\nabla\psi\|_2-1\bigr)=0, \qquad \psi(x,0)=\phi_0(x),

where τ\tau is artificial time. Numerical implementations often regularize the sign function. The aim is to restore distance-like behavior while preserving the original zero set, although discretization can cause interface drift.

The modern numerical level-set framework was developed prominently by Stanley Osher and James Sethian in 1988. Signed distance fields became central to many subsequent methods for interface tracking.

Computation and representation

Analytic and sampled fields

Simple shapes, including spheres, planes, and boxes, admit direct distance formulas. More complex boundaries are often represented by polygonal meshes or sampled grids.

For a mesh, computing signed distance typically involves two distinct tasks:

  • finding the nearest point on the surface;
  • determining whether the query point is inside or outside.

Spatial acceleration structures reduce the cost of nearest-surface queries. Inside–outside tests may use ray intersections or winding-based methods, but their reliability depends on mesh orientation, closure, and handling of degeneracies.

A sampled signed distance field stores values on a grid or adaptive spatial structure. Interpolation provides approximate values between samples. Neither interpolated distances nor their numerical gradients are generally exact, and small features can disappear if the sampling resolution is insufficient.

Distance transforms and numerical solvers

A distance transform computes distances from grid locations to a specified set of features. Interior and exterior transforms can be combined to construct a discrete signed field. Distance to boundary pixels or voxel centers is not automatically identical to distance to a continuous boundary reconstructed from them.

The fast marching method and fast sweeping methods solve discretized eikonal equations. Their accuracy depends on the discretization, grid resolution, and boundary initialization. They differ from algorithms that compute exact Euclidean distances to a specified discrete feature set.

Truncated and learned representations

A truncated signed distance field limits stored values to a band around the surface, often by clamping them to a fixed range. It is useful in volumetric reconstruction because distant values can be discarded or compressed. Outside the unclamped band, it is no longer an exact distance function.

In learned shape representations, an artificial neural network may approximate a signed distance function from coordinates. Training can use known distances, surface samples, normal information, or an eikonal penalty such as

Leik=Ex[(∥∇fθ(x)∥2−1)2].\mathcal{L}_{\mathrm{eik}} = \mathbb{E}_x \left[ \bigl(\|\nabla f_\theta(x)\|_2-1\bigr)^2 \right].

This encourages unit gradient magnitude but does not by itself guarantee correct distances, signs, or geometry.

Shape operations and transformations

For negative-inside fields dAd_A and dBd_B, common implicit constructions are

funion=min⁡(dA,dB),f_{\mathrm{union}}=\min(d_A,d_B),
fintersection=max⁡(dA,dB),f_{\mathrm{intersection}}=\max(d_A,d_B),
fdifference=max⁡(dA,−dB).f_{\mathrm{difference}}=\max(d_A,-d_B).

These operations encode the intended Boolean combinations through their signs, subject to boundary conventions. They do not, in general, produce the exact signed distance to the resulting boundary. Coincident surfaces and degenerate combinations can also require special treatment. Thus, a field built by constructive solid geometry may be a useful implicit representation without being an exact SDF.

Rigid motions preserve distances. If QQ is an orthogonal matrix and tt is a translation, the transformed field is

d′(x)=dΩ(QT(x−t)).d'(x)=d_\Omega\bigl(Q^{T}(x-t)\bigr).

For uniform scaling by s>0s>0,

dsΩ(x)=s dΩ(x/s).d_{s\Omega}(x)=s\,d_\Omega(x/s).

Nonuniform scaling generally requires more than composing the original field with an inverse transformation: different directions undergo different length changes, so exact distance is usually lost.

Applications and limitations

Signed distance functions support collision detection, geometric offsets, shape optimization, surface reconstruction, and simulations involving moving boundaries. Their gradients provide useful contact normals and geometric derivatives where the field is differentiable.

In rendering, sphere tracing advances a ray using distance information. An exact distance gives a radius within which no surface is present, allowing a step that does not cross the surface. A conservative lower bound can also support safe stepping; an overestimated distance can skip an intersection. Sphere tracing was developed as a rendering method by John C. Hart in the 1990s.

Distance fields are also used to render scalable text and vector shapes. A sampled field allows coverage near a contour to be estimated from distance, although sharp corners and fine details may require specialized representations.

Important limitations include:

  • Geometric singularities: gradients and curvature may be undefined at corners, medial axes, or other singular points.
  • Ambiguous interiors: open, nonorientable, or self-intersecting surfaces may not define a unique sign.
  • Sampling error: finite resolution can remove thin structures, merge nearby surfaces, or distort topology.
  • Loss of exactness: interpolation, Boolean combinations, learned approximation, and deformation can preserve a useful zero set while violating distance properties.
  • Storage and evaluation cost: dense grids become expensive in three dimensions, while sparse or procedural representations introduce their own computational trade-offs.