Bellaard.com

Distance Fields

By: Gijs Bellaard

Definition

A distance field is defined as a function \(f_\O: \R^n \to \R\) that returns for every point \(x\) the closest distance to the proper set \( \emptyset \neq \O \subset \R^n\). When the distance field only returns the distance to ''one'' object, i.e. \(\O\) is connected, then we talk of a distance function. We say a distance field is signed when it returns the signed distance to the closest point on the surface of the objects, \(\partial \O\). In mathematical terms : \[ f_\O(x)= \begin{cases} -d(x,\partial \O) & \text{if \(x \in \O\)}\\ d(x,\partial \O) & \text{if \(x \not\in \O\)}\\ \end{cases} \] Where \(d(x,S)\), for some set \(S\) and a point \(x\), is defined to be \(\inf_{s \in S} d(x,s)\), and \(d(x, y)\) the standard euclidean distance between \(x\) and \(y\). We will discuss signed distance fields in this article.

Properties

\[ \text{ \(f\) is continious everywhere }\] \[ \text{\(\rot{f} = 1\) almost everywhere} \]

Operation

Proper Operations

The following operations are "proper" in the sense that they are actual equalities.

Complement

We define the complement set \(\O^C := \{ x \in \R^n \mid x \not\in \O \}\). Its distance field is simply: \[ f_{\O^C} = -f_\O\]

Offseting

Let \(o \in \R^n\) be some vector. We define the offseted set \(\O+o := \{x + o \mid x \in \O\}\). Its distance field is: \[ f_{\O+o}(x) = f_\O(x-o)\]

Scaling

Let \(s \in \R\) be some scalar. We define the scaled set \(s\O := \{sx \mid x \in \O \}\). Its distance field is: \[ f_{s\O}(x) = f_\O(x/s)\cdot s\]

Rotating and/or Mirroring

Let \(R \in R^{n \times n}\) be some orthogonal matrix. We define the transformed set \(R\O := \{Rx \mid x \in \O\}\). Its distance field is: \[ f_{R\O}(x) = f_\O(R^{-1}x) = f_\O(R^Tx)\] A specific case is when \(R\) effectivily mirrors about some plane with normal \(n\). We denote such a matrix with \(M_n\) and can be written as \( I - 2nn^T \). In this case the math simplifies a bit because \(M_n^T = M_n\): \[ f_{M_n\O}(x) = f_\O(x - 2n(n\cdot x)) \]

Acceptable Operations

The following operations do not maintain the distance field completely and are therefor not equalities. They are, however, "acceptable" in that they never return a bigger distance than in truth.

Union

\[ f_{\O_1 \cup \O_2} \approx \min\Par{f_{\O_1},f_{\O_2}}\]

Intersection

\[ f_{\O_1 \cap \O_2} \approx \max\Par{f_{\O_1},f_{\O_2}}\]

Unfolding and Folding

A fold \(M^+_n\) is a conditional reflection about some plane with normal \(n\): \[ M^+_nx := \begin{cases} x & \text{if } n\cdot x > 0\\ M_nx & \text{otherwise} \end{cases} \] it's called a fold because it "folds" the input such that it is on the "positive" side of \(n\). let \(\O_{\cdot n \geq 0}\) be the subset of \(\O\) of vectors that are on the positive side of some normal \(n\). An unfold \(U_n\) about the plane with normal \(n\) is defined as: \[ U_n\O := \O_{\cdot n \geq 0} \cup M_n\O_{\cdot n \geq 0} \] That is the set that is left when we disregard everything on the negative side of \(n\) and unflip the positive side unto the negative side. Its distance field is: \[ f_{U_n\O}(x) \approx f_\O(M^+_nx)\]

Barely Working Operations

Inversion

Let \(x^I := x/|x|^2\). We define the inverted set \( \O^I := \{ x^I \mid x \in \O\}\) \[ f_{\O^I}(x) \approx f(x^I)|x|^2 \]