SDF-Based Sphere Collider

In the Signed Distance section, we introduced analytical representations of solid geometries—where shapes like spheres, boxes, and half-spaces are defined using mathematical expressions on their coordinates. One powerful abstraction introduced there was the Signed Distance Function (SDF). This function evaluates, at any given point in space, the signed distance to the surface of a geometry: negative values indicate points inside the object, positive values are outside, and zero lies exactly on the surface.

This concept translates naturally into collision detection and boundary condition enforcement in simulation frameworks like MPM.

Representing a Collider with Analytic SDF

Consider a 2D sphere (circle) with center and radius . Its SDF is defined as:

  • If , the point is inside the sphere.
  • If , the point is on the sphere’s surface.
  • If , the point is outside the sphere.

This definition allows us to apply contact boundary conditions uniformly across the simulation domain by evaluating the SDF at each grid node.

Implementation 31.2.1 (Sphere SDF Collider with Frictional Contact, simulator.py).

            # a sphere SDF as boundary condition
            sphere_center = ti.Vector([0.5, 0.5])
            sphere_radius = 0.05 + dx # add a dx-gap to avoid penetration
            if (x_i - sphere_center).norm() < sphere_radius:
                normal = (x_i - sphere_center).normalized()
                diff_vel = -grid_v[i, j]
                dotnv = normal.dot(diff_vel)
                dotnv_frac = dotnv * (1.0 - sdf_friction)
                grid_v[i, j] += diff_vel * sdf_friction + normal * dotnv_frac