Dual Contouring
Hermite Data Elements:
1class HermiteData:2 def __init__(self, point, normal):3 self.point = point # Exact intersection coordinate on grid edge4 self.normal = normal # Normal vector of surface at intersection56def dual_contouring_cell(cell):7 # Collect Hermite data along all 12 cell edges8 points, normals = [], []9 for edge in cell.edges:10 if edge.is_intersected:11 points.append(edge.intersection_pt)12 normals.append(edge.intersection_normal)1314 # Solve QEF to place one vertex inside the cell15 dual_vertex = solve_qef(points, normals)16 return dual_vertex
Marching Cubes is a primal method that puts vertices directly on grid edges. Dual Contouring is a dual method that places exactly one vertex inside each cell containing a surface crossing, reconstructing sharp corners and edges.
QEF Mathematics:
E(v) = ∑ (n_i · (v - p_i))^2, representing distance to tangent planes. 2. Least Squares Form: A is the matrix of normal vectors n_i, and b_i = n_i · p_i. 3. Feature Alignment: The solver places the vertex exactly at the intersection of the tangent planes, capturing sharp corners.1import numpy as np23def solve_qef(intersection_points, normals):4 # Formulate Ax = b system5 # A contains normals, b contains dot product (normal * point)6 A = np.array(normals)7 b = np.array([np.dot(n, p) for n, p in zip(normals, intersection_points)])89 # Solve linear least squares system10 # minimizes sum((n_i * (x - p_i))^2)11 x, _, _, _ = np.linalg.lstsq(A, b, rcond=None)12 return x
To find the ideal position for the dual vertex, we minimize the sum of squared distances to the tangent planes at each edge intersection point. This is formulated as a linear least squares problem A v = b and solved using pseudo-inverses.
Related Concepts
Frenet-Serret orthonormal frames, curvature and torsion, inflection flipping, and Bishop parallel transport frames.
The Weingarten shape operator, eigenvalues κ₁ and κ₂, orthogonal principal curvature directions, and quad-remeshing lines.
3D Grids and Marching Cubes.