This repository will generate gears and other 3d models in stl format using C++
A powerful C++ library for generating high-quality 3D gear models with accurate involute tooth profiles. Export directly to STL format for 3D printing, CNC machining, or mechanical design visualization.
- 🦷 True Involute Tooth Profiles - Mathematically accurate gear teeth based on engineering standards
- 📐 Multiple Pressure Angles - Support for 14.5°, 20°, 25° and custom angles
- ⚙️ Four Gear Types - Spur, Helical, Bevel, and Worm gears
- 🎨 Flexible Tooth Styles - Involute, rounded, or simple rectangular teeth
- 🕳️ Center Hole Support - Optional shaft holes with configurable diameter
- 📤 STL Export - Direct export to industry-standard STL format
- 🎯 Fully Parametric - Control every aspect of gear geometry
The most common type - flat gears with straight teeth parallel to the axis.
- Use case: Parallel shaft transmission
- Advantages: Simple, efficient, cost-effective
- Applications: Clocks, washing machines, mechanical toys
Gears with angled teeth that form a helix around the gear body.
- Use case: High-speed parallel shafts
- Advantages: Smoother, quieter operation; higher load capacity
- Applications: Car transmissions, industrial machinery
Cone-shaped gears for transmitting motion between intersecting shafts.
- Use case: 90° angle transmission
- Advantages: Changes rotation axis direction
- Applications: Hand drills, differential gears, printing presses
The pressure angle determines how gear teeth interact and affects strength, smoothness, and bearing loads.
| Pressure Angle | Smoothness | Tooth Strength | Bearing Load | Best For |
|---|---|---|---|---|
| 14.5° | ⭐⭐⭐⭐⭐ Very Smooth | ⭐⭐ Low | ⭐⭐ Low | Light-duty, legacy systems |
| 20° | ⭐⭐⭐⭐ Smooth | ⭐⭐⭐⭐ High | ⭐⭐⭐ Medium | Standard choice - Most applications |
| 25° | ⭐⭐⭐ Less Smooth | ⭐⭐⭐⭐⭐ Very High | ⭐⭐⭐⭐ High | Heavy-duty industrial systems |
Visual Comparison:
- 14.5° → Wider, thicker teeth (gentle curves)
- 20° → Balanced medium teeth (industry standard)
- 25° → Narrower, pointed teeth (stronger, more force)
- C++ compiler with C++11 support (g++, clang++, MSVC)
- Standard C++ library (no external dependencies!)
# Linux/macOS
g++ -std=c++11 -O2 main.cpp -o main
# Windows (MSVC)
cl /std:c++11 /O2 main.cpp
# With warnings
g++ -std=c++11 -O2 -Wall -Wextra main.cpp -o main# Run the generator
./main
# Output files will be created in the current directory
# gear_pressure_20.stl, gear_helical.stl, etc.struct GearParams {
int numTeeth; // Number of teeth (minimum: 3)
float innerRadius; // Root radius (valley depth)
float pitchRadius; // Working radius where gears mesh
float outerRadius; // Tip radius (tooth height)
float thickness; // Gear thickness/width
float toothWidth; // Tooth width ratio (0.0-1.0)
int segments; // Smoothness (higher = smoother)
GearType type; // SPUR, HELICAL, BEVEL, WORM
float helixAngle; // Twist angle for helical gears (degrees)
float pressureAngle; // 14.5°, 20°, or 25° typical
bool useInvolute; // true = engineering profile
bool roundedTeeth; // true = simplified rounded teeth
float roundingRadius; // Rounding amount for rounded teeth
float holeRadius; // Center hole size (0 = solid)
};- Minimum: 3 teeth
- Typical: 12-80 teeth
- Rule: Fewer teeth = larger/chunkier, more teeth = smaller/finer
- innerRadius: Root circle - typically 70-80% of pitch radius
- pitchRadius: The "working" diameter - main dimension
- outerRadius: Tip circle - typically 110-115% of pitch radius
- Range: 0.3 to 0.5
- Standard: 0.45 (45% tooth, 55% gap)
- Higher: Stronger teeth but may cause interference
- Low (2-3): Fast generation, blocky appearance
- Medium (4-6): Good balance (recommended)
- High (8+): Very smooth but slower, larger files
- 14.5°: Smooth, quiet, weak (older standard)
- 20°: Standard modern gears ⭐ RECOMMENDED
- 25°: Strong, handles high loads
GearParams standardGear = {
20, // 20 teeth
35.0f, // Inner radius
45.0f, // Pitch radius
50.0f, // Outer radius
10.0f, // Thickness
0.45f, // Tooth width
4, // Segments
SPUR, // Type
0, // No helix angle
20.0f, // 20° pressure angle
true, // Use involute
false, // Not rounded
2.0f, // Rounding (unused)
8.0f // Center hole
};
std::ofstream file("my_gear.stl");
file << "solid my_gear\n";
generateGear(file, standardGear);
file << "endsolid my_gear\n";
file.close();GearParams helicalGear = {
24, // 24 teeth
38.0f, // Inner radius
48.0f, // Pitch radius
53.0f, // Outer radius
20.0f, // Thicker for helix
0.45f, // Tooth width
4, // Segments
HELICAL, // Helical type
30.0f, // 30° helix angle
20.0f, // 20° pressure angle
true, // Use involute
false, // Not rounded
2.0f, // Rounding (unused)
12.0f // Larger center hole
};GearParams strongGear = {
18, // 18 teeth
40.0f, // Inner radius
50.0f, // Pitch radius
55.0f, // Outer radius
15.0f, // Thicker body
0.45f, // Tooth width
5, // Smoother
SPUR, // Type
0, // No helix
25.0f, // 25° for strength!
true, // Use involute
false, // Not rounded
2.0f, // Rounding (unused)
10.0f // Center hole
};GearParams wormGear = {
3, // 3 thread starts
8.0f, // Inner radius
12.0f, // Pitch radius
15.0f, // Outer radius
80.0f, // Long body
0.3f, // Thread width
8, // High smoothness
WORM, // Worm type
0, // (unused for worm)
20.0f, // Pressure angle
false, // Special worm profile
false, // Not rounded
2.0f, // Rounding (unused)
5.0f // Center hole
};For two gears to mesh properly:
- Same pressure angle - Both must use identical pressure angles
- Same pitch radius ratio - Gear ratio = teeth ratio
- Complementary helix angles - One positive, one negative (helical)
// Gear 1: 20 teeth, 40mm pitch radius
GearParams gear1 = {20, 30.0f, 40.0f, 45.0f, ...};
// Gear 2: 40 teeth, 80mm pitch radius (2:1 ratio)
GearParams gear2 = {40, 70.0f, 80.0f, 85.0f, ...};GearParams printable = {
numTeeth: 16, // Not too many
segments: 4, // Medium quality
thickness: 8.0f, // At least 3-5mm
holeRadius: 4.0f, // For 8mm shaft with tolerance
useInvolute: true, // Better meshing
pressureAngle: 20.0f // Standard
};GearParams decorative = {
numTeeth: 12,
segments: 6, // Higher for visual quality
roundedTeeth: true, // Smoother look
holeRadius: 0, // Solid for mounting
thickness: 5.0f // Thinner for wall mounting
};The library generates ASCII STL files with the following structure:
solid gear_name
facet normal nx ny nz
outer loop
vertex x1 y1 z1
vertex x2 y2 z2
vertex x3 y3 z3
endloop
endfacet
...
endsolid gear_name
File sizes:
- Simple gear (20 teeth, 4 segments): ~500 KB
- Complex gear (40 teeth, 8 segments): ~2-3 MB
- Worm gear (long body): ~1-2 MB
The library implements true involute curves using the involute function:
inv(α) = tan(α) - α
Where α is the pressure angle. This ensures:
- ✅ Constant velocity ratio during meshing
- ✅ Smooth power transmission
- ✅ Industry-standard tooth profiles
Teeth automatically narrow from root to tip based on:
toothAngleAtRadius = toothAngleAtPitch × (pitchRadius / currentRadius)This creates the characteristic curved involute profile where higher pressure angles produce more pronounced narrowing.
Solution: Increase segments parameter (try 5-8)
Solution: Decrease segments parameter or reduce numTeeth
Solution: Ensure innerRadius < pitchRadius < outerRadius and useInvolute = true
Solution:
- Use same pressure angle for both gears
- Check pitch radius ratio matches teeth ratio
- Ensure proper center distance
Solution:
# Add M_PI definition if needed
g++ -D_USE_MATH_DEFINES main.cppInvolute gears are the industry standard because:
- Constant velocity ratio - No speed fluctuation
- Center distance tolerance - Works with slight variations
- Easy manufacturing - Can be cut with standard tools
- Efficient power transmission - Minimal friction losses
| Aspect | 14.5° | 20° | 25° |
|---|---|---|---|
| Tooth thickness | Thickest | Medium | Thinnest |
| Contact ratio | Highest | Medium | Lowest |
| Radial force | Lowest | Medium | Highest |
| Bending strength | Lowest | Medium | Highest |
- Gear Theory Basics
- Involute Curve Mathematics
- AGMA Standards (American Gear Manufacturers Association)
- 3D Printing Gears Guide
Contributions are welcome! Areas for improvement:
- Binary STL output for smaller files
- Gear pair meshing validation
- Internal/ring gear support
- Rack gear generation
- Epicyclic/planetary gear systems
- Automatic tolerance calculation
- GUI parameter interface
- Batch generation tools
This project is open source. Feel free to use, modify, and distribute for both personal and commercial projects.
Based on classical involute gear theory and mechanical engineering principles. Inspired by the need for accessible, high-quality parametric gear generation tools.
- Issues: Open an issue on GitHub
- Questions: Check the examples and parameter reference
- Feature Requests: Submit via GitHub issues
Made with ⚙️ by engineers, for engineers
Generate, print, and build amazing mechanical systems!