Let’s model a carbon nanotube! This post is meant to be a supplemental explanation for the OpenSCAD code I published to parametrically model an armchair carbon nanotube.
While designing a shelf to store my 3D prints, I became fixated on the efficiency and stability of hexagons. I wanted to created another hexagonal structure to organize my desk and thought of a carbon nanotube inspired pen holder. Searching online, I saw several available models, but none that allowed me to parametrically generate the structure. That’s when I thought to create my own parametrically generated carbon nanotube.
First, I need to figure out if the geometry is printable using an FDM printer. In terms of geometry, a carbon nanotube is a wall of tessellated hexagons rolled into a cylinder. Let’s take a look at the regular hexagon to examine the overhangs it forms when printed vertically.
Hexagon Overhang Comparison
There are different angles one can use to roll a graphene sheet into a carbon nanotube. In the armchair configuration, the overhang section bends away from the z-axis at 30° before meeting at a bridge. Not ideal, but I know from my printer benchmarks that it can handle overhangs under 45° and bridges under small distances. In the zigzag configuration, there are no bridges, but the overhang bends away from the z-axis at a 60° angle. It might be possible to print this at a slow speed with active cooling, but to work within the known limits of my printer, I chose to go with the armchair configuration. There’s also a chiral configuration, but the covalent bond angles are much easier to reason with in the armchair configuration.
I wanted to be able to easily adjust my bridge lengths, so I examined the dimensions of a regular hexagon in terms of its edge lengths.
Hexagon Dimensions
This gives us the height and width we need to draw the honeycomb pattern formed by the graphene sheets.
Hexagon Vertex Grid
We can actually fit the vertices into a grid where the the carbon atoms have uniform vertical spacing and are horizontally spaced alternating between whole and half edge lengths. Now, we need roll this sheet into a tube. I wanted my carbon nanotube to have an arbitrary number of faces so let’s take a look the properties of a regular polygon.
Regular Polygon Overhead View
If this was a zigzag configuration, using a regular polygon for overhead view dimensions would suffice because the vertices would be evenly distributed. However, this is the armchair configuration so we need to modify this regular polygon such that edge lengths alternate between whole and half lengths. If we cut off every vertex so that the cut faces form this alternating length pattern, then we will have the shape of the tube from an overhead view.
Regular Polygon Cuts
With these values, we can place the atoms and bonds in position. My initial OpenSCAD implementation threw all the geometry into the workspace and tried to compile them all at once. The preview was fast, but this initial design never finished rendering so I needed to structure my design in a more computationally efficient manner. Through some research, I learned that OpenSCAD allows users to cache geometry for future calls so I added aggressive caching throughout my code. The end result is a model that finishes rendering in under a minute for medium sized models. You can check out the model at Thingiverse.
If you lead a busy life, you should learn how to juggle. The physical activity is great for stress relief, but I also mean juggling in the sense of multitasking. Knowing how to efficiently allocate time between tasks is a valuable skill to have. We juggle jobs, tasks, family, and friends as if they were tangible things that we could throw and catch. Though just a figure of speech, delving into juggling as metaphor reveals some interesting ways to think about concurrent tasks.
Juggling, like music, is steeped in patterns that can be described using math. From siteswap to temporal logic, there are many ways to think about juggling patterns. One of the more obscure descriptions I wanted to explore is Shannon’s juggling theorem. I was first introduced to this formula when it was offhandedly mentioned during a weekly juggling session at the UW Juggling Club. The equation is as follows:
(F + D) H = (V + D) B
where
F = Flight time of a ball
D = Dwell time that a ball spends in a hand
V = Vacant time that a hand spends empty
B = Number of balls
H = Number of hands
Formulated by Claude Shannon, this equation describes how the collective time of the balls relates to the collective time of the hands. If we examine one juggling cycle (i.e. one iteration where every ball passes through each hand) and trace through said cycle from the hand and the ball perspective, we can derive the equation. Without the insight to watch just a ball or just a hand, it’s hard to decipher the relationship from merely watching someone juggle.
3 Ball Cascade
I could never fully grasp the equation by juggling until I started to imagine the time values as coloured bars of varying length. To show you what I see, I’ve coded up a visualizer to illustrate the timing of all the juggling events happening in the clip above.
The diagram consists of three ball timelines and two hand timelines.
We can observe that the ball has two states: in a hand and in the air. On a ball timeline, the time a ball spends in a hand (D) is coloured and the time the ball is in the air (F) is left blank. As for the hands, we can observe that it also has two states: holding a ball and empty. When the hand is holding a ball (D), the timeline is coloured using the colour of the ball being held. The rest of the hand timeline is blank (V) meaning the hand is empty.
With this diagram, we can start to play around with the timing relationships. In one cycle, we can see that a ball is thrown and caught once by each hand (i.e. “(F + D) H” meaning a ball trip happens H times) and a hand throws and catches each ball once (i.e. “(V + D) B” meaning a hand trip happens B times). The coloured area in all the ball timelines is equivalent to the coloured area in all the hand timelines because the time a ball spends in a hand is the same as the time a hand spends holding a ball. As we play with this equation, we can see how various aspects of the juggling pattern are temporally related.
If we start throwing the balls higher, the coloured portions of the ball timeline will proportionally shrink as the ball spends more time in the air and, consequently, the hands will spend more time empty.
If we add two more balls, we will see flight times increase because the balls will be thrown higher. On the other hand, there will be less vacant time as the juggler gets busy trying to accommodate the new balls.
This is a neat observation that does not have any practical value, but it is an interesting way to think about juggling. Coincidentally, I learned about Shannon’s juggling theorem around the same time I was attending lectures on concurrent programming. I developed a hunch that juggling and concurrency were related, but didn’t explore the relationship much. It wasn’t until a few semesters later that I was reminded of the topic during a lecture on computer systems performance analysis. The arithmetic used in the lecture felt somewhat similar to the juggling formula so I decided to revisit it.
Let’s reframe the equation I described in terms of computation.
Let’s say there are three threads and two processors.
For simplicity, we can observe that the thread has two states: processing and suspended. On a thread timeline, the time a thread spends in a processor is coloured in and the time a thread is suspended is left blank.
As for the processors, we can observe that it also has two states: processing and idle. When it is processing a thread, I have coloured in the timeline using the colour of the thread it identifies. The rest of the processor timeline is blank meaning the processor is not processing a thread.
The coloured area of all the thread timelines is equivalent to the coloured area of all the processor timelines because the time a thread spends in execution is the same as the time a processor spends processing it.
The concepts map onto this problem domain nicely. You could also apply the math on other scenarios involving two interacting parties. Let’s say there is a group of patients at a hospital that need to go through a fixed set of medical examinations. If you reframe patients as balls and examination rooms as hands, you can start to apply the same intuition to it. However, the equation wouldn’t exactly work in this case because of some assumptions we have made.
Shannon’s Juggling Theorem is a succinct equation because it is meant to describe a cascade pattern where every ball cycles through each hand. It assumes that there is at most one ball in a hand at any given time. The equation does not account for multiplexing where multiple balls are thrown and caught at the same time. Additionally, if we changed the pattern so that some balls are thrown higher than others, then the ball trips would not have a uniform length. Simply multiplying by the number of trips would instead become a sum of all the trip times. Even though the equation requires throws of equal height (i.e. round-robin scheduling) to work, the intuition behind it still holds in the case there balls are thrown different heights.
You could generalize this intuition to any two sided system where each side has a set amount of time interacting and not interacting. This works because of double-counting the set of time from each perspective and equating the two sides. It makes sense when you start manipulating the variables at the aggregate level. For example, if you add more patients to the hospital scenario above while holding the number of examination rooms the same, you will increase the aggregate wait time of the patients. This increase is especially apparent if you view the system from patients’ perspective.
My takeaway from Shannon’s insight is to think in the other perspective. Given what you know about your side of the equation, you might be able to imagine what it’s like on the other side of the system. Whether you’re figuring out multitasking with processors or multitasking with daily life, I recommend thinking not just in terms of the juggler, but also the juggled. Think not only of your schedule, but that of others. Hopefully, this perspective will help you navigate the juggling patterns of life. After all, life is a juggling act.
Additional Reading:
The Science Of Juggling Peter J. Beek and Arthur Lewbel in Scientific American, Vol. 18, Issue 4, pages 92-97; November 1995.