def create_involute_gear(module, num_teeth, pressure_angle=20, thickness=10):
Generate a parametric involute spur gear.
- module: Gear module (pitch diameter / number of teeth) in mm
- num_teeth: Number of teeth
- pressure_angle: Pressure angle in degrees (typically 20°)
- thickness: Gear thickness in mm
Returns: FreeCAD Part object
# Calculate gear geometry
pitch_diameter = module * num_teeth
pitch_radius = pitch_diameter / 2.0
pressure_angle_rad = math.radians(pressure_angle)
base_radius = pitch_radius * math.cos(pressure_angle_rad)
addendum = module # Height above pitch circle
dedendum = 1.25 * module # Depth below pitch circle
outer_radius = pitch_radius + addendum
root_radius = pitch_radius - dedendum
tooth_angle = 2 * math.pi / num_teeth
# Generate one tooth profile
def involute_point(theta):
"""Generate point on involute curve"""
x = base_radius * (math.cos(theta) + theta * math.sin(theta))
y = base_radius * (math.sin(theta) - theta * math.cos(theta))
for tooth_num in range(num_teeth):
angle_offset = tooth_num * tooth_angle
# Generate involute curve points (from base circle to outer)
theta_end = math.sqrt((outer_radius / base_radius)**2 - 1)
for i in range(20): # 20 points per involute curve
theta = theta_start + (theta_end - theta_start) * i / 19.0
x, y = involute_point(theta)
# Rotate to tooth position
x_rot = x * math.cos(angle_offset) - y * math.sin(angle_offset)
y_rot = x * math.sin(angle_offset) + y * math.cos(angle_offset)
involute_points.append(App.Vector(x_rot, y_rot, 0))
# Create tooth profile wire
# (Simplified - real implementation would include root fillet, mirror, etc.)
tooth_curve = Part.BSplineCurve()
tooth_curve.interpolate(involute_points)
teeth_wires.append(tooth_curve.toShape())
# Create gear body (simplified - circular approximation)
# In production code, would build precise tooth profiles
gear_circle = Part.makeCircle(pitch_radius)
gear_face = Part.Face(Part.Wire(gear_circle))
gear_solid = gear_face.extrude(App.Vector(0, 0, thickness))
gear = create_involute_gear(module=2.5, num_teeth=24, thickness=10)
Part.show(gear, "InvoluteGear")
print("✓ Involute gear generated!")
print(f" Pitch diameter: {2.5 * 24} mm")
print(f" Number of teeth: 24")
Comments