Piston-Driven Wheel Simulation

Edit: I noticed a small mistake in the formulas below. I’ll try to get it fixed this week.

I visited a railroad museum today, and I saw a display showing how the piston is linked to the train wheel. For fun and learning I wanted to model the basic mathematics of how the linkage moves with the wheel and the piston, without looking up the answer on the Internet. That part seemed very simple:

Since l and p are fixed length, it was a matter of simple trigonometry, as seen above. Then I threw the math into a simple Racket program to simulate the movement. That part not hard, but it took an hour or two to add enough lines and circles to make the graphic look half-way decent. Here is a video recording of it running (about 10 seconds):

Here is the source code packaged with the video:


One interesting part of the math is the connection point of l and p (see the diagram above). Until you get very long lengths of l, you get something close to the cosine function but not quite the same.