{
  "id": "signed-distance-function",
  "title": "Signed distance function",
  "lang": "en",
  "source_lang": "en",
  "summary": "A signed distance function assigns each point its distance to a boundary, with opposite signs inside and outside the region it encloses.",
  "category": "mathematics",
  "subcategory": "geometry",
  "type": "concept",
  "aliases": [
    "Signed distance field",
    "SDF"
  ],
  "generated_at": "2026-11-05",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/signed-distance-function/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/signed-distance-function/",
      "json": "https://aiwiki.page/zh/signed-distance-function.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "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."
    },
    {
      "heading": "Definition and sign conventions",
      "text": "Let \\(\\Omega\\) be a nonempty proper open subset of Euclidean space \\(\\mathbb{R}^n\\), with nonempty boundary \\(\\partial\\Omega\\). The unsigned distance from a point \\(x\\) to a nonempty set \\(A\\) is\n\n\\[\\operatorname{dist}(x,A)=\\inf_{y\\in A}\\|x-y\\|_2,\\]\n\nwhere \\(\\|\\cdot\\|_2\\) denotes Euclidean distance from the origin.\n\nUnder the negative-inside convention, the signed distance function is\n\n\\[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}\\]\n\nHere \\(\\overline{\\Omega}\\) denotes the closure of \\(\\Omega\\). An equivalent formula is\n\n\\[d_\\Omega(x) = \\operatorname{dist}(x,\\Omega) - \\operatorname{dist}(x,\\mathbb{R}^n\\setminus\\Omega).\\]\n\nSome 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.\n\nThe 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."
    },
    {
      "heading": "Elementary examples",
      "text": "For a ball of radius \\(R>0\\) centered at \\(c\\),\n\n\\[\\Omega=\\{x:\\|x-c\\|_2<R\\},\\]\n\nthe signed distance is\n\n\\[d_\\Omega(x)=\\|x-c\\|_2-R.\\]\n\nIt is negative inside the ball, zero on the sphere, and positive outside.\n\nFor a half-space\n\n\\[\\Omega=\\{x:a\\cdot x<b\\}, \\qquad \\|a\\|_2=1,\\]\n\nthe signed distance is\n\n\\[d_\\Omega(x)=a\\cdot x-b.\\]\n\nThe normalization of \\(a\\) is essential. Without it, the expression still identifies the boundary and its two sides but generally does not measure distance.\n\nThis distinction separates a signed distance function from a general implicit function. For example,\n\n\\[f(x)=\\|x-c\\|_2^2-R^2\\]\n\nhas the same zero set and signs as the ball’s signed distance, but its magnitude is not the distance to the sphere."
    },
    {
      "heading": "Mathematical properties",
      "text": "Continuity and differentiability\n\nA signed distance function in Euclidean space is 1-Lipschitz:\n\n\\[|d_\\Omega(x)-d_\\Omega(y)|\\leq \\|x-y\\|_2.\\]\n\nFor 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.\n\nConsequently, 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.\n\nNondifferentiability 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 \\(C^2\\) boundary admits a tubular neighborhood in which the signed distance is \\(C^2\\).\n\nThe eikonal equation\n\nWhere signed distance is differentiable, its gradient has unit magnitude:\n\n\\[\\|\\nabla d_\\Omega(x)\\|_2=1.\\]\n\nThis is the eikonal equation with unit speed. It expresses that distance increases at unit rate along the direction normal to an equidistant surface.\n\nThe equation is usually considered separately on the interior and exterior, with boundary data \\(d_\\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.\n\nA 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.\n\nNormals, projections, and curvature\n\nWith negative values inside, the gradient on a smooth boundary gives its outward unit normal:\n\n\\[n(x)=\\nabla d_\\Omega(x), \\qquad x\\in\\partial\\Omega.\\]\n\nIn a neighborhood where a point \\(x\\) has a unique nearest boundary point, that point is\n\n\\[p(x)=x-d_\\Omega(x)\\nabla d_\\Omega(x).\\]\n\nThe second derivatives encode curvature. On the boundary, under the convention that a sphere with outward normal has positive principal curvatures,\n\n\\[\\Delta d_\\Omega = \\operatorname{div}(\\nabla d_\\Omega)\\]\n\nequals 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."
    },
    {
      "heading": "Level sets and moving interfaces",
      "text": "A signed distance function represents a boundary implicitly as\n\n\\[\\partial\\Omega=\\{x:d_\\Omega(x)=0\\}.\\]\n\nMore generally, the sets \\(d_\\Omega(x)=r\\) describe distance offsets wherever that level is attained. Offsets can develop singularities or change topology when they encounter medial-axis structures.\n\nThe level-set method represents a moving interface as the zero set of a time-dependent function \\(\\phi(x,t)\\). If the interface moves with normal speed \\(V\\), measured in the direction of increasing \\(\\phi\\), its evolution satisfies\n\n\\[\\frac{\\partial\\phi}{\\partial t} + V\\|\\nabla\\phi\\|_2=0.\\]\n\nA 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.\n\nA common reinitialization procedure evolves an auxiliary equation such as\n\n\\[\\frac{\\partial\\psi}{\\partial\\tau} + \\operatorname{sgn}(\\phi_0) \\bigl(\\|\\nabla\\psi\\|_2-1\\bigr)=0, \\qquad \\psi(x,0)=\\phi_0(x),\\]\n\nwhere \\(\\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.\n\nThe 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."
    },
    {
      "heading": "Computation and representation",
      "text": "Analytic and sampled fields\n\nSimple shapes, including spheres, planes, and boxes, admit direct distance formulas. More complex boundaries are often represented by polygonal meshes or sampled grids.\n\nFor a mesh, computing signed distance typically involves two distinct tasks:\n\n- finding the nearest point on the surface;\n- determining whether the query point is inside or outside.\n\nSpatial 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.\n\nA 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.\n\nDistance transforms and numerical solvers\n\nA 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.\n\nThe 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.\n\nTruncated and learned representations\n\nA 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.\n\nIn 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\n\n\\[\\mathcal{L}_{\\mathrm{eik}} = \\mathbb{E}_x \\left[ \\bigl(\\|\\nabla f_\\theta(x)\\|_2-1\\bigr)^2 \\right].\\]\n\nThis encourages unit gradient magnitude but does not by itself guarantee correct distances, signs, or geometry."
    },
    {
      "heading": "Shape operations and transformations",
      "text": "For negative-inside fields \\(d_A\\) and \\(d_B\\), common implicit constructions are\n\n\\[f_{\\mathrm{union}}=\\min(d_A,d_B),\\]\n\n\\[f_{\\mathrm{intersection}}=\\max(d_A,d_B),\\]\n\n\\[f_{\\mathrm{difference}}=\\max(d_A,-d_B).\\]\n\nThese 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.\n\nRigid motions preserve distances. If \\(Q\\) is an orthogonal matrix and \\(t\\) is a translation, the transformed field is\n\n\\[d'(x)=d_\\Omega\\bigl(Q^{T}(x-t)\\bigr).\\]\n\nFor uniform scaling by \\(s>0\\),\n\n\\[d_{s\\Omega}(x)=s\\,d_\\Omega(x/s).\\]\n\nNonuniform 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."
    },
    {
      "heading": "Applications and limitations",
      "text": "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.\n\nIn 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.\n\nDistance 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.\n\nImportant limitations include:\n\n- Geometric singularities: gradients and curvature may be undefined at corners, medial axes, or other singular points.\n- Ambiguous interiors: open, nonorientable, or self-intersecting surfaces may not define a unique sign.\n- Sampling error: finite resolution can remove thin structures, merge nearby surfaces, or distort topology.\n- Loss of exactness: interpolation, Boolean combinations, learned approximation, and deformation can preserve a useful zero set while violating distance properties.\n- Storage and evaluation cost: dense grids become expensive in three dimensions, while sparse or procedural representations introduce their own computational trade-offs."
    }
  ],
  "links": [
    "mathematical-function",
    "geometry",
    "partial-differential-equation",
    "open-set",
    "euclidean-space",
    "euclidean-distance",
    "closure-topology",
    "half-space",
    "lipschitz-continuity",
    "almost-everywhere",
    "gradient",
    "hessian-matrix",
    "laplace-operator",
    "differential-geometry",
    "interpolation",
    "artificial-neural-network",
    "orthogonal-matrix"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}