liveBook · Manning

Distance

As explained in Geometry for Programmers

Distance is a nonnegative measure of separation between points or between a point and a geometric set.

A distance function assigns each point a nonnegative separation from another point or geometric set. In geometry and computation, it turns shapes into scalar fields that algorithms can evaluate and reuse. section 2.8 section 10.1.4

For a plane defined by three noncollinear points, distance can be understood as the height of a parallelepiped: signed volume divided by the base parallelogram’s area. The same result comes from projecting onto the plane’s normalized normal. section 9.4.3

A signed distance function (SDF) extends ordinary distance with a sign: it is negative inside a body and positive outside. This convention describes both a shape’s boundary and its surrounding field. section 10.1

Common geometric distance constructions include:

  • Point-to-point distance uses the Euclidean square-root formula, or an equivalent self-dot-product implementation. section 10.1.4
  • Point-to-line distance divides a parallelogram’s signed area by the line segment’s length; its absolute value gives unsigned distance. section 10.1.4
  • Point-to-segment distance checks the normalized projection: use the line distance for an interior projection and an endpoint distance otherwise. section 10.1.4
  • A rectangle SDF combines distances to its four edges and assigns the sign from the nearest edge’s supporting line. section 10.1.4
Figure 9.20 A parallelepiped formed by p2-p1, p3-p2, and p-p1, and the parallelogram formed by p2-p1, p3-p1, too
09-20

Visualizes point-to-plane distance as the height of a parallelepiped over a parallelogram base. section 9.4.3

Figure 10.2 A disk and its SDF: negative inside, positive outside
10-02

Shows an SDF for a disk, with negative values inside and positive values outside. section 10.1

How Geometry for Programmers covers it

How deep it goes
Explains geometric derivations and Python implementations for points, lines, segments, planes, and rectangles, stopping short of mesh-wide construction.
Examples
Uses point-to-plane geometry, a disk SDF, point-to-point and point-to-segment Python functions, and a rectangular SDF.
What it assumes
Assumes familiarity with points, vectors, dot products, cross products, and signed geometric quantities.
What you can do after
Build it from scratch using vector products, projections, endpoint tests, and edge signs to compute basic distance fields.
How it connects
Connects distance functions with scalar fields, vector algebra, dot products, cross products, signed distance functions, and triangle meshes.

Also explained in

Compare how 10 books explain distance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Geometry for Programmers. The section links point to the parts of the book it draws on.