Triangle wave gyroid

A gyroid is a fascinating geometric structure. It's a three-dimensionally-tileable unit that creates an infinitely connected surface. The surface is triply-periodic, meaning it repeats in all three dimensions. Gyroids also occur naturally in polymer science and biology.

For 3D printing, a gyroid is a useful infill pattern. Not only does it fill volume without using much material, but it also provides strength to the final part in all three dimensions. As an added bonus, a gyroid pattern can be built using a toolpath that never crosses itself.

In this article I present the traditional gyroid and a couple of alternatives that might work better for 3D printing.

Traditional gyroid

The gyroid surface can be approximated with trigonometric functions. It's a rather simple equation:

$$ \sin x\cos y+\sin y\cos z+\sin z\cos x=0 $$

That is, at every (x,y,z) coordinate value where that equation is zero, that point is on the surface of the gyroid. There isn't any closed-form way to solve for these points, so for display purposes we typically designate a point as being on the gyroid surface if it's within some small error distance from zero.

Here's how a single tileable gyroid unit looks, with the values x, y, and z ranging from 0 to 2π for a complete cycle on each axis, with the "zero surface" defined as wherever the result of the equation is within 0.02 units of zero:

Left mouse to rotate, right mouse to pan, scroll wheel to zoom

Here is how two units tiled in a 2×2×2 unit volume look being built up in layers:

Rather lovely to look at, isn't it?

Problem when 3D printing

Fused-deposition-manufacturing (FDM) 3D printers build an object by laying down strands of filament, layer by layer. Normally a gyroid infill pattern is printed at a small enough scale that the gyroid surface is reasonably continuous with minimal gaps or holes. Sometimes, however, one might want to print it at a really low density such as 5%, which translates to a large-scale gyroid. When the infill is printed, the parts of the gyroid that have nearly zero slope from horizontal result in significant gaps with filament loops hanging in empty space, which are likely to sag before the material cools and hardens.

I thought to myself, "The problem here is that sinusoidal functions have parts with zero or near-zero slope. What if I could make a gyroid based on a periodic function that doesn't have zero slope?"

First try with a triangle wave

What if I replaced the sine and coside functions in the gyroid equations with their analogous triangle wave functions? A triangle wave is made up of straight lines, mathematically known as a "piecewise linear" function. It's a continuous function but with discontinuous slope. While one can test the function argument to determine if the slope should be positive or negative, an easier way (programmatically) is to use trigonometric functions:

$$ \begin{array}{ll} \text{trisin}\,x = \frac{2}{\pi} \arcsin(\sin x) \\ \text{tricos}\,x = 1 - \frac{2}{\pi} \arccos(\cos x) \end{array} $$

It may not be obvioius that these functions produce triangle waves, but they do. In the domain \(0 \le x \le 2\pi\), they produce straight-line slopes ranging from -1 to +1, just like their sine and cosine counterparts, with the zeros and extrema where you expect them to be. Our new triangle-wave gyroid then becomes:

$$ \text{trisin}\,x\:\text{tricos}\,y + \text{trisin}\,y\:\text{tricos}\,z + \text{trisin}\,z\:\text{tricos}\,x = 0 $$

It looks like this.

Left mouse to rotate, right mouse to pan, scroll wheel to zoom

Okay... not quite what I expected. It does appear that I eliminated the horizontal slopes, but the surface is still curvy, and I expected a surface made of flat parts.

Eventually I figured out that the reason it's curvy is because each term in the gyroid equation is the product of two functions. Multiply a sine and cosine together and you get other variants of sine and cosines curves. But multiply two piecewise-linear functions together and you get a piecewise quadratic function. That's why it's curvy.

Second try with a triangle wave

What should I do? I spent a while thinking about this, and decided that because each of the three terms in the gyroid has the form \(\sin p \cos q\), and that expression itself is a sinosoidal function, then I need to convert that entire term to a triangle wave rather than have it be the product of two triangle waves.

Wolfram Alpha gives us this identity:

$$ \sin p \cos q = \frac{1}{2}\left( \sin(p+q) + \sin(p-q) \right) $$

That is, the product of a sine and cosine can be expressed as the sum of two sinewaves. We can substitute triangle waves for each of those sinewaves. Summed together, they result in piecewise-linear functions. Here, we can ignore the scaling of ½ because we are interested only in the gyroid surface where the sum of all terms is zero.

This means we can rewrite the gyroid equation as a simple sum of sinewaves. Therefore, the following two equations are equivalent expressions of a gyroid:

$$[\sin x\cos y] + [\sin y\cos z] + [\sin z\cos x] = 0 $$ $$ [\sin(x+y)+\sin(x-y)] + [\sin(y+z)+\sin(y-z)] + [\sin(z+x) + \sin(z-x)] = 0 $$

Each of those sine functions in the second equation can then be converted into triangle waves. Again, ignoring the scaling factor in the trisin function, the triangle-wave gyroid becomes:

$$\begin{matrix} \arcsin \left(\sin(x+y)\right)+\arcsin\left(\sin(x-y)\right) & + & \\ \arcsin \left(\sin(y+z)\right)+\arcsin\left(\sin(y-z)\right) & + & \\ \arcsin \left(\sin(z+x)\right)+\arcsin\left(\sin(z-x)\right) & = & 0 \end{matrix} $$
Left mouse to rotate, right mouse to pan, scroll wheel to zoom

That's more like I expected when I started out on this project!

In fact, now that we have expressed a gyroid as a simple sum of sine functions, we can substitue any continuous or piecewise-continuous periodic function for the sine and get a gyroid shaped by that function.

What about 3D printing?

I accomplished what I set out to do. While this article turned out rather short to read, I actually started this project a few years ago and revisited it a couple of times. I tried, and failed, to figure out how to implement this gyroid in the PrusaSlicer code. I kept getting strange discontinuities in the result, trying to adapt the original gyroid slicing code. Maybe someone smarter than me can do it someday.

For 3D printing, it's good that the horizontal parts of the original gyroid aren't present in my creation here. However, it is possible that the slopes are still too shallow where the original gyroid was horizontal. Eyballing it, they look like they would meet the 45° rule if the surface was stretched vertically by a factor of two. Here's how it would look, showing 2×2×2 gyroid units:

Left mouse to rotate, right mouse to pan, scroll wheel to zoom

That would still provide strength in all three directions, although the vertical direction would likely have more compression strength.

It would be nice if I could see this implemented! Not just for infill, but for some decorative projects I have in mind.


Popular posts from this blog

Syncing Office 365 Outlook to Google calendar using Power Automate

New approach to screw threads in OpenSCAD

Whose hands are biggest? You may be surprised.