Bolts in Mathematica
March 4, 2025 at 9:32 AM by Dr. Drang
Yesterday’s post included three drawings I made using a combination of Mathematica, Acorn, and OmniGraffle. The roles that Acorn and OmniGraffle played were pretty obvious, but the Mathematica1 part is worth a description.
To get the stylized images of bolts, I combined three things:
- A black helix representing the thread peak.
- A blue helix representing the thread valley.
- A translucent cylinder representing the bolt shank.
The cylinder was easy. There’s a Cylinder
function built in to Mathematica. But the helices require a little math.
A helix can be defined through a set of parametric equations:
where , , , and are constants that define the geometry of the helix and is the single parameter whose value changes as we wind around the helix. This is a more complicated set of equations than are given in MathWorld’s Helix article, but that’s because we need to account for the “handedness” and the starting angles of the threads.
Here’s the Mathematica notebook with all the code needed to produce the drawings:
(The final three drawings in the notebook aren’t being rendered correctly here. I’ll discuss that in a bit.)
The notebook starts by defining the dimensions of a 1″ UNC bolt. The major diameter is 1″, the minor diameter is 0.8647″, and the pitch is 0.125″. These values are turned into the variables ro
, ri
, and p
. We then create the black helix via the ParametricPlot3D
function with equations
The negative sign in the equation for is what makes this helix right-handed instead of left-handed.
The blue helix is built the same way, but from the equations
Here, we need to include a starting angle of to insure that the peaks and valleys are 180° apart.
Unfortunately, the graphics in the rest of the embedded notebook above aren’t being rendered properly, even though the code is correct. The translucent cylinder by itself should look like this:
The three parts shown together in a perspective view with the bolt in a vertical orientation should look like this:
And the orthographic view, which is what I used to build the images in yesterday’s post, should look like this:
I don’t know why the embedded view isn’t accounting properly for the AmbientLight
directive. The three images above are what I see in my local notebook. The embedded notebook is coming from the Wolfram Cloud, which apparently needs to get some bugs fixed. I’ll have to send in a report.
The orthographic view was arrived at by setting the ViewPoint
to {0, ∞, 0}
. In other words, we’re looking down the y-axis from an infinite distance. In doing this, all the sight lines become parallel, which is what we need to see the thread alignment without any perspective effects.
After saving the orthographic view as a PNG image, I opened it in Acorn, selected all the white pixels with the Magic Wand tool, and turned them transparent. I then imported two copies of the transparent PNG into OmniGraffle, arranged them so the threads meshed, and added the annotations shown in yesterday’s post.
I suppose I could have done all the drawing in Mathematica, but that would’ve taken more time than just drawing one bolt there and doing all the subsequent manipulations in other apps. I try to choose apps based on what they’re good at.
-
Although the app on my Mac is now named Wolfram, it’s still called Mathematica in several places within the app and in online seminars run by Wolfram (the company). Thirty-five years of branding are hard to break. ↩