Instantly share code, notes, and snippets.

Last active March 17, 2020 16:10
Star You must be signed in to star a gist
Gear generation code with openSCAD

In order to use this code, you will need to copy gears.scad to your Libraries folder. https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Libraries

And then you can run Untitled.scad as any other normal scad project file.

If you don't want to mess around with the library, just combine the two code files together into one.

Library Functions

This code will provide a function

spur_gear()

Which takes the following parameters:

• N = Number of teeth
• P = Diametral Pitch (defaults to 12)
• pa = Pressure Angle (defaults to 14.5)

The output of this method will be a 2D gear (converted to mm) which you simply need to linear_extrude in order to print on a 3D printer.

The library also includes a number of other mathematical functions including:

calc_center_distance()

Which takes the following parameters:

• N1 = Tooth count of the first gear
• N2 = Tooth count of the second gear
• P = Diametral Pitch

The output of this function will be the mm distance you must space both gears for them to mesh perfectly.

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 include Teeth = 18; Pitch = 12; linear_extrude(6) difference() { spur_gear(N=Teeth, P=Pitch); circle(d=19.1); } // Change this variable to calculate how far // this gear and another gear need to be spaced // in order to mesh properly. // (output will display in the console in units mm) OtherGearTeeth = 37; echo("***"); echo("center distance (mm)", calc_center_distance(Teeth, OtherGearTeeth, Pitch)); echo("***");
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters