This is related to very simple code to generate the simplest type of gear only, namely a straight-toothed spur gear where the teeth follow a correct "involute" path.
I took Leemon Baird's work from the year 2011 and fixed some things. In particular I added an accessor function for the root radius (which is needed for my cutaway drawings), and I devised a more intelligent way to create polyhedron overlaps, which results in smaller STL files (no "jaggies") and should result in better CPU usage characteristics in preview/F5 mode. In addition, it was apparent that the order of union/linear_extrude/for_loop in Leemon's original code prevented it from doing the right thing in many cases (at least in my cases). I originally had to modify his code just to get it to a state of being usable.
The exactness of Leemon Baird's involute gear tooth profile is demonstrated in this Youtube short: https://www.youtube.com/shorts/dTZVvh20y7M The above animation was generated in OpenSCAD but it uses models generated in CadQuery, those models having been created with the CadQuery variant of the gear generation code we're discussing here (in other words the same formulas are used in generation of those models).
This straight-toothed spur gear generation code is for those who want an extremely lightweight solution which does not import dependencies which may be considered by some to be excessive. The code is only about 200 lines. It is available here: https://sourceforge.net/p/nl10/code/HEAD/tree/scad/gears/common/invol-spur-gear.scad The library consists of this single file. This code is "introduced" or "presented" in this Youtube video: https://www.youtube.com/watch?v=woMjFXVkY_w
Again I'm leaving this for y'all because I'm moving in a slightly different direction, away from OpenSCAD and towards CadQuery. I want to give what some may find to be useful/lightweight.
Cheers and happy coding.
Sent with Proton Mail secure email.