Machine Design with Python
Design real mechanical parts in code: stress and deflection, beams and shafts, the gears and gear trains at the heart of every machine, cams, springs, and bearings, finishing with a complete gearbox design. Every result is a number you can check against the handbook.
10 projects, 250 hands-on levels, run in your browser.
Syllabus
- Stress & Strain: Every machine part carries loads, and every design starts by checking that the stress stays safely below what the material can take. Compute axial, shear, and bearing stress, relate stress to strain through the elastic modulus, apply a factor of safety, and account for thermal effects. The capstone sizes a tension member. Units throughout: newtons, millimetres, and MPa (N/mm^2).
- Beam Bending: Beams carry transverse loads by bending. Find the support reactions and the maximum bending moment, compute a cross-section's moment of inertia and section modulus, turn the moment into a bending stress, and predict deflection. The capstone sizes a loaded beam. Units: N, mm, MPa; moments in N*mm, inertia in mm^4.
- Shafts & Torsion: Shafts transmit power by twisting. Compute the polar moment, the shear stress and angle of twist, the torque a shaft carries at a given power and speed, and the diameter needed to carry it safely, including shafts under combined bending and torsion. The capstone sizes a power shaft. Torque in N*mm, length in mm, stress in MPa.
- Spur Gears: Gears are the heart of mechanical power transmission. Lay out spur-gear geometry from the module and tooth count, work out speed and torque ratios, resolve the forces on a tooth at the pressure angle, and touch the involute geometry that lets gears mesh smoothly. The capstone analyzes a complete gear pair. Lengths in mm, angles in degrees, the standard 20 degree pressure angle.
- Gear Trains & Planetary: Chain gears together for large ratios. Compute simple and compound train ratios, handle the planetary (epicyclic) gear set with the Willis equation, track torque and efficiency through the stages, and design a train for a target ratio. The capstone analyzes a two-stage reducer.
- Gear Strength: A gear tooth is a tiny cantilever beam that must survive both bending and surface wear. Use the Lewis equation for bending stress, a velocity factor for dynamic load, and the Buckingham wear load for surface durability, then size the gear's power capacity and check it. The capstone verifies a gear tooth against both failure modes.
- Cams & Followers: A cam turns rotation into a programmed back-and-forth motion of a follower. Build the displacement diagram, then the velocity and acceleration of simple-harmonic and cycloidal motion laws, and check the cam's geometry and pressure angle. The capstone analyzes a follower through a full rise. Angles in radians, lift in mm, cam speed in rad/s.
- Springs: Helical springs store energy and apply controlled forces. Compute the spring rate from the wire and coil geometry, the deflection under load, the shear stress (with the Wahl correction for curvature), the stored energy, and combinations of springs. The capstone designs a compression spring. Lengths in mm, force in N, stress in MPa, G = 80000 MPa for steel.
- Bearings & Fatigue: Machines fail over time, not just at first load. Rate rolling-element bearings by their L10 life, and check shafts against fatigue with the endurance limit, stress concentration, and the Goodman criterion for combined mean and alternating stress. The capstone checks a bearing and a shaft together. Loads in N, stress in MPa.
- Capstone: Single-Stage Gearbox Design: The finale. Design a complete single-stage spur gearbox from a power and ratio spec: lay out the gears, find the loads, size the shaft against combined bending and torsion, select a bearing for the required life, and assemble the whole design into one report. Every formula here was built in the earlier projects. Power in kW, speed in rpm, lengths in mm, stress in MPa.
Key concepts
- Cam motion law: The displacement profile a cam gives its follower: uniform, simple-harmonic (SHM), or cycloidal. Cycloidal motion has zero acceleration at the transitions, so…
- Factor of safety: The ratio of a material's strength to the working stress ( n = S/sigma ). The allowable stress is the strength divided by the chosen factor of safety; a pa…
- Gear ratio: The driven gear's teeth over the driver's ( i = N2/N1 ). A reduction ratio above 1 divides the speed and multiplies the torque; compound trains multipl…
- Goodman criterion: A fatigue check combining the alternating stress (against the endurance limit) and the mean stress (against the ultimate strength): sa/Se + sm/Sut <= 1/n .…
- Involute: The tooth profile that lets gears transmit motion at a constant ratio. It is generated from the base circle ( d_b = d cos(phi) ); the involute function is inv(…
- L10 bearing life: The life 90 percent of rolling bearings survive, in millions of revolutions: L10 = (C/P)^p (p = 3 for ball bearings). Because of the cube, doubling the load cu…
- Lewis equation: Treats a gear tooth as a cantilever beam, giving its bending stress sigma = Ft/(b m Y) , where Y is the form factor. With a velocity factor for dynamic load, i…
- Module: The fundamental size of a metric gear tooth: pitch diameter over the number of teeth ( m = d/N ). Two gears must share a module to mesh, and the pitch diameter…
- Pressure angle: The angle between the line of action and the direction of motion, in a gear mesh or a cam-follower contact. It measures how much force is wasted as side-thrust…
- Section modulus: A cross-section's Z = I/c , packaging the moment of inertia and the distance to the outer fibre. Bending stress is simply M/Z , so a larger Z carries more…
- Spring rate: A spring's stiffness, force per unit deflection ( k = G d^4 / (8 D^3 N) for a helical spring). The shear stress is corrected by the Wahl factor for the cur…
- Stress: Internal force per unit area (force over area), in MPa. Normal stress acts along an axis; shear stress acts across a section. Every design checks that stress s…
- Willis equation: The kinematic relation for a planetary (epicyclic) gear set, relating the sun, ring, and carrier speeds. Solved for the carrier it is a tooth-weighted average…