Building procedural revolver cylinders for fun and profit

I’m on vacation, which means I jump on any fun side project I can think of. Having just gotten a VR headset, I was playing Hot Dogs, Horseshoes and Hand Grenades when I started pondering the geometry of revolver cylinders. I quickly decided it’d be cool to implement a system that can generate a 3D model of a cylinder of any given size and chamber number. That’s what I’m going to talk about today.

This is what we’ll be making:

# The constraints

Let’s start by defining some constraints. A cylinder of radius 1 with chambers of radius 100 doesn’t make sense, so our system needs to take that into account.

Our cylinder is going to look something like this:

Where:

• $$A$$ is the center of the cylinder
• $$R$$ is the radius of the cylinder
• $$Rc$$ is the radius of a single chamber (half of the caliber)
• $$n$$ is the number of chambers (in this example, 6)

We want to make sure that:

1. The outer wall of the chamber ($$\lvert DE \rvert$$) has a reasonable thickness.
2. The walls between consecutive chambers ($$\lvert FG \rvert$$) have a reasonable thickness.

Looking around, I found this document, indicating that a good ballpark for minimum chamber wall thickness would be somewhere around a third of the chamber diameter - we’re looking for an $$R$$ such that $$\lvert DE \rvert > \frac{2}{3}Rc$$.

Let’s start with the first constraint. We can easily see that $$\lvert DE \rvert = \frac{R}{2} - 2Rc$$. Shuffling the terms around gives:

That’s our answer for the first constraint. Simple enough!

How about the other constraint? We can see in the image that $$\lvert FG \rvert = \lvert CC’ \rvert - 2Rc$$. Although the triangle $$\triangle ACC’$$ in the image is equilateral, this is only the case for $$n=6$$, so we cannot make use of that. However, we know the angle $$\alpha$$, and that will come in especially handy. The law of cosines gives us:

Knowing that $$\lvert AC \rvert = \lvert AC’ \rvert = \frac{R}{2} + Rc$$, and $$\alpha = \frac{2 \pi}{n}$$:

Let’s call the part with the cosine $$x$$:

For $$\lvert FG \rvert$$ to be greater than or equal to $$\frac{2}{3}Rc$$:

As an example, let’s try six chambers:

Let’s try nine chambers!

So, for nine chambers, our $$R$$ should be at least $$5.79606Rc$$.

# Getting into the groove

Revolver cylinders often have a notable feature we’re forgetting here - the grooves cut between chambers on the outside. Let’s figure out how to do the other side of the cylinder, where the grooves sit!

This is how the result should look:

We’re going to cut circles that intersect the cylinder at right angles into it halfway between each pair of chambers. Here’s what’s new:

• The first thing we can see is that I’m using a five-chamber cylinder as the example for this section, since it’s easier to see that $$N$$ lies outside of the cylinder.
• $$K$$ is the midpoint of $$CC’$$. This also means that $$AK$$ bisects the angle $$\alpha$$.
• $$I$$ is the midpoint of $$C’K$$. Note that this is a complete asspull - if we wanted to have wider grooves, we’d pick a point that’s closer to $$C’$$, if we wanted narrower grooves we’d pick a point that’s closer to $$K$$. I feel like choosing the midpoint of $$C’K$$ gives good results here.
• $$L$$ is the intersection of the line $$AI$$ with the cylinder.
• $$N$$ lies at the intersection of the line $$AK$$ and the tangent to the cylinder that passes through $$L$$.
• Our groove is a circle with center $$N$$ and radius $$Rn$$
• $$\lvert C’M \rvert = \lvert CE \rvert$$

We want to find $$\lvert AN \rvert$$ and $$Rn$$.

Let’s start by finding $$\lvert C’K \rvert$$.

Noticing that $$\triangle AKC’$$ and $$\triangle AKI$$ are right-angled, we can find the angle $$\angle AKI$$ if we know $$\lvert AK \rvert$$. Let’s do that real quick, with the help of our friend Pythagoras.

Knowing that $$\angle ANL = \frac{ \pi }{2} - \angle IAK$$ we can finally look for $$\lvert AN \rvert$$ and $$Rn$$. From the law of sines:

Now for $$\lvert C’N \rvert$$. Law of cosines:

# What have we learned

This all looks very scary, but it’s pretty quick to do in code. But what does it actually mean?

For a cylinder with $$n$$ chambers, every $$\frac{\pi}{n}$$ radians we alternately:

1. Cut out a circle of radius $$Rc$$,
$$\lvert AC \rvert = \frac{R}{2} + Rc$$ away from the center of the cylinder - these are the chambers.
2. Cut out a circle of radius $$Rn$$, $$\lvert AN \rvert$$ away from the center of the cylinder - these are the grooves running down the sides of the cylinder.

You can find an example implementation in the source code for this page’s demo! Next week we’ll look into how to turn this into a three-dimensional model.