This is an alpha-type Stirling engine: a hot piston and a cold piston, each on their own crank throw, sharing one flywheel with the cold piston's crank set 90° ahead of the hot piston's. Piston position is the real slider-crank trigonometric relation x(θ) = r(1 − cos θ) for crank angle θ.
- Pressure comes from the ideal gas law applied to a fixed, sealed charge of gas split between a hot-side volume (temperature Th) and a cold-side volume (Tc): P = nR / (Vhot/Th + Vcold/Tc). As the crank turns, both volumes change and the split between them shifts, so P swings with θ.
- Torque on the crank is the real mechanical consequence of that pressure pushing on both pistons: τgas(θ) = (P − Patm)·(dVhot/dθ + dVcold/dθ). This is computed fresh every physics step — nothing about the rotation is scripted.
- The flywheel obeys Newton's law for rotation: I·dω/dt = τgas − τfriction − τload. Its angle then advances by ω·dt, feeding back into the piston positions for the next step.
Because the average gas torque over one revolution grows with Th − Tc, the engine only keeps spinning once that gap is large enough to beat friction and the load you set — exactly like a real Stirling engine, it needs a kick to get going and can stall if the temperature gap collapses or the load is too high.