Skip to content

Signed Distance (Sdf.m)

Signed Distance Fields (SDFs) have been widely applied in various areas of computer graphics, including the representation of implicit surfaces12, collision detection in robotics34. In particular, SDFs have gained attention for their use in implicit modeling5, a technique for representing 3D shapes as continuous functions, rather than discrete mesh descriptions.

In Sorotoki, SDFs are implemented in the class Sdf.m and can be used to construct general 2D and 3D geometries. They can also be utilized to model static or dynamic contact environments, generate 3D models of soft actuators that are suitable for 3D printing, and compute inertia tensors for continuum bodies in R2 and R3.

Implicit modeling using SDFs.

We briefly outline the mathematical foundations underpinning the Sdf class. As the name suggests, signed distance functions are a type of function that encodes distance information relative to an object defined implicitly. Adopting the notation used in Reiner1, given a domain ΩRn and its boundary Ω, these functions can be written in the following general form:

sdf(p)={d(p,Ω)if pΩ,+d(p,Ω)if pRnΩ,

where d(p,Ω):=infyΩ||py||2 is a scalar function that returns the smallest Euclidean distance from a sample point pRn to the boundary Ω.

SDFs provide a simple and efficient way of determining the location of a set of points relative to a domain Ω defined implicitly. The SDF is a scalar function that encodes the Euclidean distance of a sample point pRn to the boundary Ω of the domain. By evaluating the sign of the SDF, it is possible to classify the set of points as being within or outside the boundary of the domain. This enables set operations such as union, difference, and intersection to be performed.

Example: Unit-circle and evaluation

Image title

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
% distance function
f = @(x) sqrt( x(:,1).^2 + x(:,2).^2 ) - 1.0;

% assigning @f to Sdf class
sdf = Sdf(f,'BdBox',[-2 2 -2 2]);

% generate samples
X = linspacen([0;0],[1;1],5).';

% eval SDF
D = S.eval(X);
disp( D(:,end).' );

sdf.show(); 
fplot(X,'k.','MarkerSize',30);
output
-1.0000, -0.6464, -0.2929, 0.0607, 0.4142

Example: Unit-circle intersect

Image title

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
% distance function
f = @(x) sqrt( x(:,1).^2 + x(:,2).^2 ) - 1.0;

% assigning @f to Sdf class
sdf = Sdf(f,'BdBox',[-2 2 -2 2]);

% generate samples
X = linspacen([0;0],[1;1],5).';

% eval SDF
I = sdf.intersect(X);

sdf.show(); 
fplot(X(I,:),'m.','MarkerSize',30);
fplot(X(~I,:),'k.','MarkerSize',30);


  1. Tim Reiner, Gregor M\ifmmode \ddot u\else ü\fi ckl, and Carsten Dachsbacher. Interactive modeling of implicit surfaces using a direct visualization approach with signed distance functions. Computers & Graphics, 35(3):596–603, 2011. doi:10.1016/j.cag.2011.03.010

  2. Zhiqin Chen and Hao Zhang. Learning Implicit Fields for Generative Shape Modeling. ArXiv e-prints, 2018. arXiv:1812.02822, doi:10.48550/arXiv.1812.02822

  3. Joseph Ortiz, Alexander Clegg, Jing Dong, Edgar Sucar, David Novotny, Michael Zollhoefer, and Mustafa Mukadam. iSDF: Real-Time Neural Signed Distance Fields for Robot Perception. ArXiv e-prints, 2022. arXiv:2204.02296, doi:10.48550/arXiv.2204.02296

  4. Puze Liu, Kuo Zhang, Davide Tateo, Snehal Jauhri, Jan Peters, and Georgia Chalvatzaki. Regularized Deep Signed Distance Fields for Reactive Motion Generation. ArXiv e-prints, 2022. arXiv:2203.04739, doi:10.48550/arXiv.2203.04739

  5. Lawrence Smith and Robert MacCurdy. SoRoForge: End-to-End Soft Actuator Design. IEEE Transactions on Automation Science and Engineering, pages 1–12, 2023. doi:10.1109/TASE.2023.3241866