-
-
Save Satyam/a0baa6dec7dffdb17327 to your computer and use it in GitHub Desktop.
The gear calculation in Gear.ko turned into a function and used to design a couple of gears
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
""" | |
examples/gearing.ko | |
Turned the gear example into a generic function | |
to produce solid gears. | |
See gear.ko for description and notes for the original function. | |
This function takes | |
R: radius of the gear. | |
z0 and z1: top and bottom elevation to produce the thickness of the gear | |
nt: number of teeth of the gear. Defaults to 32 | |
pressureAngle: defaults to 20, an industry standard. See tutorial. | |
clearance: extra depth to compensate for fillet produce by the tool. | |
1.157 in US, 1.1666 in EU | |
Returns a full 3D shape that can be manipulated just like any other. | |
To make a hole for the axis, you can just substract a cylinder from it. | |
Though the radius doesn't produce any visible feature on the gear, | |
it is what should be used in calculations about how this gear | |
engages other gears. It is the radius a toothless gear, that is, | |
a wheel, would have to roll on another toothless gear. | |
The involute gear construction is based on the tutorial at | |
http://www.cartertools.com/involute.html | |
""" | |
from math import sqrt, atan2, sin, cos, pi, radians | |
import operator | |
from koko.lib.shapes import * | |
def gear(R, z0, z1, nt = 32, pressureAngle = 20, clearance = 1.16666): | |
P = nt / R / 2 # diametral pitch | |
RB = R*cos(radians(pressureAngle)) # base circle radius | |
a = 1/P # addendum | |
d = clearance/P # dedendum | |
RO = R+a # outer radius | |
RR = R-d # root radius | |
# MathTree expressions for r and r**2 | |
r_2 = MathTree.square(X) + MathTree.square(Y) | |
r = MathTree.sqrt(r_2) | |
# See note (1) for derivation of tooth rotation | |
t = sqrt(R**2/RB**2 -1) | |
rot = atan2(sin(t)-t*cos(t), cos(t)+t*sin(t)) + pi/2/nt | |
# See note (2) for derivation of involute curve | |
tooth = ( | |
MathTree.sqrt(r_2-RB**2) - RB*(MathTree.atan(Y/X) + | |
MathTree.acos(RB/r)) - RB*rot | |
) | |
tooth.shape = True | |
tooth &= reflect_y(tooth) | |
# If we have an odd number of teeth, then we can't take | |
# advantage of bilateral tooth symmetry. | |
if nt % 2: | |
tooth &= -X | |
teeth = reduce(operator.add, [rotate(tooth, i*360./nt) | |
for i in range(nt)]) | |
else: | |
teeth = reduce(operator.add, [rotate(tooth, i*360./nt) | |
for i in range(nt/2)]) | |
teeth += circle(0, 0, RR) | |
teeth &= circle(0, 0, RO) | |
teeth.bounds = circle(0, 0, RO).bounds | |
teeth = extrusion(teeth, z0, z1) | |
return teeth | |
# Simple test: | |
#Number of teeth and radius of first gear | |
nt1 = 32 | |
r1 = 20. | |
#Number of teeth and radius of second gear | |
nt2 = 16 | |
r2 = 10. | |
#height of both | |
z0 = -1. | |
z1 = 1. | |
#diameter of hole | |
axld = 1 | |
g1 = gear(r1, z0, z1, nt1) | |
g1.color = 'blue' | |
g1 -=cylinder(0, 0, z0, z1, axld) | |
g2 = gear(r2, z0, z1, nt2) | |
g2 -= cylinder(0, 0, z0, z1, axld) | |
g2.color = 'red' | |
if not nt2 % 2: | |
g2 = rotate(g2, 180. / nt2) | |
g2 = move(g2, r1 + r2, 0, 0) | |
cad.shapes = g1, g2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment