SurfZar Deep-Dive: Differential Geometry Probing (Gaussian & Mean Curvature), Implicit CSG & Watertight 3D Printing
Computer GraphicsTypeScript & WebOctober 12, 2026• 5 min read

SurfZar Deep-Dive: Differential Geometry Probing (Gaussian & Mean Curvature), Implicit CSG & Watertight 3D Printing

Table of Contents (4 sections)▸

In our earlier articles on iSurfer and SurfZar, we explored how WebGL2 fragment shaders ray-trace implicit algebraic surfaces f(x,y,z)=0f(x, y, z) = 0 in real time.

However, a true mathematical laboratory needs more than visual rendering:

  1. Differential Geometry Inspection (SurfacePointProbe.ts): When a mathematician or student clicks any point on a 3D surface, what is the exact Tangent Plane, Gaussian Curvature (KK), Mean Curvature (HH), and local surface classification (elliptic, hyperbolic, parabolic, planar, or singularity)?
  2. Constructive Solid Geometry (CSG) & Homotopy Morphing (MeshExporter.ts): How do we combine two algebraic equations f1(p)=0f_1(\mathbf{p}) = 0 and f2(p)=0f_2(\mathbf{p}) = 0 via boolean operations, smooth organic blends, or continuous topological homotopies?
  3. Watertight 3D Printing: How do you turn an infinitely thin mathematical zero-set f(x,y,z)=0f(x, y, z) = 0 clipped by a bounding sphere into a solid, manifold STL/OBJ/GLB sculpture that a 3D printer slicer (Bambu Studio, PrusaSlicer) can actually print?

Here is how those three subsystems work under the hood in SurfZar.

SurfZar Studio — Inspecting and morphing high-genus algebraic manifoldsClick to zoomSurfZar Studio — Inspecting and morphing high-genus algebraic manifolds


1. Computing Gaussian (KK) & Mean (HH) Curvature Without Surface Parameterization#

In classical differential geometry textbooks, curvature is usually taught using a parametric surface patch r(u,v)\mathbf{r}(u, v) via the First and Second Fundamental Forms.

But for an implicit algebraic surface f(x,y,z)=0f(x, y, z) = 0 (such as the Barth Sextic or Gyroid), no global (u,v)(u, v) parameterization exists!

In src/lib/SurfacePointProbe.ts (computeDifferentialGeometryAtPoint), when a user clicks on the 3D canvas, we cast a picking ray r(t)=o+td\mathbf{r}(t) = \mathbf{o} + t\mathbf{d}, refine the intersection point p∗=(x,y,z)\mathbf{p}^* = (x, y, z) via Newton-Bisection, and compute the gradient vector ∇f\nabla f and the symmetric 3×33 \times 3 Hessian matrix Hf\mathbf{H}_f using central finite-difference stencils:

∇f=[fxfyfz],Hf=[fxxfxyfxzfxyfyyfyzfxzfyzfzz]\nabla f = \begin{bmatrix} f_x \\ f_y \\ f_z \end{bmatrix}, \quad \mathbf{H}_f = \begin{bmatrix} f_{xx} & f_{xy} & f_{xz} \\ f_{xy} & f_{yy} & f_{yz} \\ f_{xz} & f_{yz} & f_{zz} \end{bmatrix}

The Implicit Curvature Determinants#

Using the classical adjugate Hessian / bordered Hessian formulas for implicit surfaces, we compute the Gaussian Curvature K=κ1κ2K = \kappa_1 \kappa_2 and Mean Curvature H=12(κ1+κ2)H = \frac{1}{2}(\kappa_1 + \kappa_2) directly from ∇f\nabla f and Hf\mathbf{H}_f in R3\mathbb{R}^3:

K=−1∥∇f∥4det⁡[fxxfxyfxzfxfxyfyyfyzfyfxzfyzfzzfzfxfyfz0]K = -\frac{1}{\|\nabla f\|^4} \det \begin{bmatrix} f_{xx} & f_{xy} & f_{xz} & f_x \\ f_{xy} & f_{yy} & f_{yz} & f_y \\ f_{xz} & f_{yz} & f_{zz} & f_z \\ f_x & f_y & f_z & 0 \end{bmatrix}

H=−∇f⊤Hf∇f−∥∇f∥2tr⁡(Hf)2∥∇f∥3H = -\frac{\nabla f^\top \mathbf{H}_f \nabla f - \|\nabla f\|^2 \operatorname{tr}(\mathbf{H}_f)}{2 \|\nabla f\|^3}

From (K,H,∥∇f∥)(K, H, \|\nabla f\|), SurfacePointProbe.ts automatically classifies the local differential geometry at the probed point:

ConditionClassificationGeometric Meaning
∥∇f(p)∥<10−4\|\nabla f(\mathbf{p})\| < 10^{-4}singularityConical double point (A1A_1), cusp, or self-intersection line
$K< \varepsilon \text{ and }
$K< \varepsilon \text{ and }
K>εK > \varepsilonellipticDome or bowl (κ1,κ2\kappa_1, \kappa_2 have the same sign)
K<−εK < -\varepsilonhyperbolicSaddle point (κ1,κ2\kappa_1, \kappa_2 have opposite signs, e.g., minimal surfaces where H=0H = 0)

And from the unit normal n=∇f/∥∇f∥\mathbf{n} = \nabla f / \|\nabla f\|, it formats the exact Tangent Plane equation at p∗\mathbf{p}^*:

nx(X−x0)+ny(Y−y0)+nz(Z−z0)=0n_x(X - x_0) + n_y(Y - y_0) + n_z(Z - z_0) = 0


2. Implicit CSG Booleans, Smooth Blending & Homotopy Continuation#

Because implicit surfaces represent geometry as scalar fields f:R3→Rf: \mathbb{R}^3 \to \mathbb{R}, buildCompositeEvalFn (src/lib/MeshExporter.ts) can combine a primary equation f1(p)f_1(\mathbf{p}) and secondary equation f2(p)f_2(\mathbf{p}) into a composite scalar field F(p)F(\mathbf{p}) both in the GLSL shader and in the mesh exporter:

  1. Exact Ricci CSG Booleans:
    • Union (S1∪S2\mathcal{S}_1 \cup \mathcal{S}_2): F(p)=min⁡(f1(p), f2(p))F(\mathbf{p}) = \min(f_1(\mathbf{p}),\, f_2(\mathbf{p}))
    • Intersection (S1∩S2\mathcal{S}_1 \cap \mathcal{S}_2): F(p)=max⁡(f1(p), f2(p))F(\mathbf{p}) = \max(f_1(\mathbf{p}),\, f_2(\mathbf{p}))
    • Difference (S1∖S2\mathcal{S}_1 \setminus \mathcal{S}_2): F(p)=max⁡(f1(p), −f2(p))F(\mathbf{p}) = \max(f_1(\mathbf{p}),\, -f_2(\mathbf{p}))
  2. C1C^1-Continuous Smooth Minimum (smooth_blend): To create organic fillets where two algebraic surfaces meet, we apply polynomial smooth-minimum blending with radius k>0k > 0: h=clamp⁡(0.5+0.5⋅(f2−f1)k, 0.0, 1.0)h = \operatorname{clamp}\left(0.5 + \frac{0.5 \cdot (f_2 - f_1)}{k},\, 0.0,\, 1.0\right) F(p)=mix⁡(f2,f1,h)−k⋅h⋅(1.0−h)F(\mathbf{p}) = \operatorname{mix}(f_2, f_1, h) - k \cdot h \cdot (1.0 - h)
  3. Homotopy Continuation (λ∈[0,1]\lambda \in [0, 1]): Enabling Homotopy mode constructs the convex linear combination: Fλ(p)=(1−λ)f1(p)+λf2(p)=0F_\lambda(\mathbf{p}) = (1 - \lambda) f_1(\mathbf{p}) + \lambda f_2(\mathbf{p}) = 0 Animating λ\lambda from 0→10 \to 1 lets users watch a sphere (x2+y2+z2−1=0x^2+y^2+z^2-1=0) continuously deform its genus and bifurcate into the 65-node Barth Sextic!

3. Turning Zero-Thickness Surfaces into Watertight 3D Prints (shellThickness)#

Here is a classic trap when exporting an implicit surface f(x,y,z)=0f(x, y, z) = 0 for 3D printing:

  • A surface like the Gyroid (sin⁡xcos⁡y+sin⁡ycos⁡z+sin⁡zcos⁡x=0\sin x \cos y + \sin y \cos z + \sin z \cos x = 0) or Steiner's Roman Surface is an open, infinitely thin 2D sheet clipped by a bounding sphere or cube.
  • If you run Marching Cubes directly on f(x,y,z)=0f(x, y, z) = 0 inside [−B,B]3[-B, B]^3, the resulting mesh has zero thickness and open boundary edges where the surface hits the bounding box walls. Every 3D printer slicer rejects open, non-manifold sheets!

To make any algebraic or transcendental surface immediately 3D-printable (src/lib/MeshExporter.ts), we implemented Implicit Offset Shell Thickening (shellThickness τ>0\tau > 0) combined with Boundary Envelope Capping:

Fshell(p)=max⁡(∣f(p)∣−τ,  ∥p∥bound−B)=0F_{\text{shell}}(\mathbf{p}) = \max\left( |f(\mathbf{p})| - \tau,\; \|\mathbf{p}\|_{\text{bound}} - B \right) = 0

  • Taking ∣f(p)∣−τ=0|f(\mathbf{p})| - \tau = 0 offsets the zero-isosurface into two parallel sheets at f(p)=+τf(\mathbf{p}) = +\tau and f(p)=−τf(\mathbf{p}) = -\tau, enclosing a solid volume of thickness 2τ2\tau.
  • Intersecting that shell (max⁡\max) with the bounding volume ∥p∥bound−B≤0\|\mathbf{p}\|_{\text{bound}} - B \le 0 automatically caps every boundary cross-section, guaranteeing that Marching Cubes extracts a 100% closed, watertight, orientable 2-manifold ready to export as binary STL, vertex-colored OBJ, or GLB (GLTFExporter).
Share or cite this engineering article