Wikipedia:Reference desk/Archives/Mathematics/2020 December 6

= December 6 =

Breaking down a gyroid into layers
I'm trying to figure out how a gyroid surface, expressed as
 * $$\sin x\cos y+\sin y\cos z+\sin z\cos x=0$$

can be sliced horizontally.

This is a solved problem, as illustrated by the figures below. The first image shows a cross section of a cube generated by a 3D printing slicer to fill a cube with a gyroid infill, clearly showing that the slicer software figured out how to break the surface down into horizontal layers. The second image shows an animation of a gyroid surface being built up vertically in steps. The third is a unit cell, which would be ideal if I could figure out how to create it with some thickness, but I thought maybe the slicing approach would be simpler. I could be wrong though.

My goal here is to see if I can create a model of a gyroid surface in OpenSCAD, which I can then use as I please as a component of a 3D object rather than structural infill. I don't know yet if that is even feasible, but if I can generate coordinates of triangular facets, I can create any object.

The equation is simple enough. To generate a layer, I just fix the z height to some value, and generate y values as a function of x. Using Wolfram Alpha to solve the equation above for y, I get:
 * $$y = 2 \pi n + 2 \tan^{-1} \left( \frac{\cos z \pm \sqrt{\sin^2 x + \cos^2 z - \cos^2 x \sin^2 z} }{\sin x - \cos x \sin z} \right) $$

The problem is, when I try to plot this, I get curves with discontinuities that look sort of like a gyroid cross section in a piecewise fashion, but clearly aren't the same.

I've been searching for days and have not found any algorithm for generating vertices or facets or cross sections of a gyroid. And in spite of the seeming simplicity of the equation I am feeling somewhat stumped. How should I approach this? ~Anachronist (talk) 02:46, 6 December 2020 (UTC)
 * I have not looked into your solution, but here is how I'd solve the gyroid equation for $$y.$$
 * First, determine $$\rho\geq 0$$ and $$\alpha$$ (modulo $$2\pi$$) such that $$\rho\cos\alpha=\cos z$$ and $$\rho\sin\alpha=\sin x.$$ This can be done by taking
 * $$\rho=\sqrt{\cos^2 z+\sin^2 x}$$ and
 * $$\alpha=\mathrm{atan2}(\sin x,\cos z).$$
 * Then the equation can be rewritten as
 * $$\rho\sin(y+\alpha)+\sin z\cos x=0.$$
 * From this equation you can see a numerical problem arising when $$\rho=0$$ (or very close to it). The values of $$\rho$$ and $$\sin z\cos x$$ cannot simultaneously be zero, however; otherwise, all values for $$y$$ would solve the equation. But assume $$|\sin z\cos x| <\varepsilon^2$$. Then $$\mathrm{min}(|\sin z|,|\cos x|)<\varepsilon$$, so
 * $$\rho\geq\mathrm{max}(|\cos z|,|\sin x|)=\sqrt{\mathrm{max}(1-\sin^2 z,1-\cos^2 x)}=\sqrt{1-\mathrm{min}(|\sin z|,|\cos x|)^2} > \sqrt{1-\varepsilon^2}.$$
 * The solution set for $$y$$ is empty whenever $$\rho<|\sin z\cos x|,$$ and the inequation implies that not attempting to solve such cases also will avoid dividing by values of $$\rho$$ that are (close to) zero.
 * Put $$\eta=-\arcsin(\rho^{{-}1}\sin z\cos x).$$ Then the solutions for $$y$$ are given by:
 * $$y=\eta-\alpha+2\pi n,$$ $$y=\pi{-}\eta-\alpha+2\pi n.$$
 * Taking the Minkowski sum of the set of triples $$(x,y,z)$$ $$+$$ a small ball will give this some thickness. Caveat lector: I have not tested this. --Lambiam 13:12, 6 December 2020 (UTC)