Geometry
Rendering the Gyroid Minimal Surface
Extracting an infinite, self-intersection-free minimal surface from a single implicit equation using the marching cubes algorithm.
Background
The gyroid is a triply-periodic minimal surface, that is, a surface that is periodic in all three spatial dimensions and has zero mean curvature at every point. It contains no straight lines and, unlike many related surfaces, does not self-intersect. It was identified by Alan Schoen at NASA in 1970. The gyroid occurs in a number of physical systems, including the microstructure of certain butterfly wing scales and self-assembled block copolymers, and it is widely used as an infill geometry in additive manufacturing on account of its high stiffness-to-weight ratio and full connectivity.
Mathematical formulation
The gyroid admits a compact approximation as the zero level set of a single trigonometric field:
sin(x)·cos(y) + sin(y)·cos(z) + sin(z)·cos(x) = 0
Every point at which this expression evaluates to zero lies on the surface. The remaining task is therefore to sample the scalar field on a regular grid and extract its zero isosurface.
Implementation
The implementation is a short script based on NumPy and scikit-image. The scalar field is evaluated on a 50 × 50 × 50 grid over the domain [−π, π]³. The marching cubes algorithm is then applied at level zero to extract the isosurface as a triangulated mesh, which is rendered with Matplotlib.
grid_size = 50 x = np.linspace(-np.pi, np.pi, grid_size) X, Y, Z = np.meshgrid(x, x, x) gyroid = np.sin(X)*np.cos(Y) + np.sin(Y)*np.cos(Z) + np.sin(Z)*np.cos(X) verts, faces, normals, values = measure.marching_cubes(gyroid, level=0) ax.plot_trisurf(verts[:,0], verts[:,1], verts[:,2], triangles=faces, cmap='viridis')
Increasing grid_size yields a smoother reconstruction at the cost of additional memory and computation, while widening the sampling domain reproduces additional periods of the unit cell.