|
2 | 2 | // A rotating machine part having cut teeth or, in the case of a cogwheel, inserted teeth (called cogs), which mesh with another toothed part to transmit torque. Geared devices can change the speed, torque, and direction of a power source. The two elements that define a gear are its circular shape and the teeth that are integrated into its outer edge, which are designed to fit into the teeth of another gear.
|
3 | 3 |
|
4 | 4 | // Set units
|
5 |
| -@settings(defaultLengthUnit = in, kclVersion = 1.0) |
| 5 | +@settings(defaultLengthUnit = in) |
6 | 6 |
|
7 |
| -// Define parameters |
8 |
| -nTeeth = 21 |
9 |
| -module = 0.5 |
10 |
| -pitchDiameter = module * nTeeth |
11 |
| -pressureAngle = 20 |
12 |
| -addendum = module |
13 |
| -deddendum = 1.25 * module |
14 |
| -baseDiameter = pitchDiameter * cos(pressureAngle) |
15 |
| -tipDiameter = pitchDiameter + 2 * module |
16 |
| -gearHeight = 3 |
| 7 | +// Define a function to create a spur gear |
| 8 | +fn spurGear(nTeeth, module, pressureAngle, gearHeight) { |
| 9 | + // Define gear parameters |
| 10 | + pitchDiameter = module * nTeeth |
| 11 | + addendum = module |
| 12 | + deddendum = 1.25 * module |
| 13 | + baseDiameter = pitchDiameter * cos(pressureAngle) |
| 14 | + tipDiameter = pitchDiameter + 2 * module |
17 | 15 |
|
18 |
| -// Interpolate points along the involute curve |
19 |
| -cmo = 101 |
20 |
| -rs = map( |
21 |
| - [0..cmo], |
22 |
| - f = fn(@i) { |
23 |
| - return baseDiameter / 2 + i / cmo * (tipDiameter - baseDiameter) / 2 |
24 |
| - }, |
25 |
| -) |
26 |
| - |
27 |
| -// Calculate operating pressure angle |
28 |
| -angles = map( |
29 |
| - rs, |
30 |
| - f = fn(@r) { |
31 |
| - return units::toDegrees(acos(baseDiameter / 2 / r)) |
32 |
| - }, |
33 |
| -) |
| 16 | + // Define the constants of the keyway and the bore hole |
| 17 | + keywayWidth = 2 |
| 18 | + keywayDepth = keywayWidth / 2 |
| 19 | + holeDiam = 5 |
| 20 | + holeRadius = holeDiam / 2 |
| 21 | + startAngle = asin(keywayWidth / 2 / holeRadius) |
34 | 22 |
|
35 |
| -// Calculate the involute function |
36 |
| -invas = map( |
37 |
| - angles, |
38 |
| - f = fn(@a) { |
39 |
| - return tan(a) - units::toRadians(a) |
40 |
| - }, |
41 |
| -) |
| 23 | + // Sketch the keyway and center hole |
| 24 | + holeWithKeyway = startSketchOn(XY) |
| 25 | + |> startProfile(at = [ |
| 26 | + holeRadius * cos(startAngle), |
| 27 | + holeRadius * sin(startAngle) |
| 28 | + ]) |
| 29 | + |> xLine(length = keywayDepth) |
| 30 | + |> yLine(length = -keywayWidth) |
| 31 | + |> xLine(length = -keywayDepth) |
| 32 | + |> arc(angleStart = -1 * startAngle + 360, angleEnd = 180, radius = holeRadius) |
| 33 | + |> arc(angleStart = 180, angleEnd = startAngle, radius = holeRadius) |
| 34 | + |> close() |
42 | 35 |
|
43 |
| -// Map the involute curve |
44 |
| -xs = map( |
45 |
| - [0..cmo], |
46 |
| - f = fn(@i) { |
47 |
| - return rs[i] * cos(invas[i]: number(rad)) |
48 |
| - }, |
49 |
| -) |
50 |
| - |
51 |
| -ys = map( |
52 |
| - [0..cmo], |
53 |
| - f = fn(@i) { |
54 |
| - return rs[i] * sin(invas[i]: number(rad)) |
55 |
| - }, |
56 |
| -) |
| 36 | + // Using the gear parameters, sketch an involute tooth spanning from the base diameter to the tip diameter |
| 37 | + gearSketch = startSketchOn(XY) |
| 38 | + |> startProfile(at = polar(angle = 0, length = baseDiameter / 2)) |
| 39 | + |> involuteCircular( |
| 40 | + startRadius = baseDiameter / 2, |
| 41 | + endRadius = tipDiameter / 2, |
| 42 | + angle = 0, |
| 43 | + tag = $seg01, |
| 44 | + ) |
| 45 | + |> line(endAbsolute = polar(angle = 160 / nTeeth, length = tipDiameter / 2)) |
| 46 | + |> involuteCircular( |
| 47 | + startRadius = baseDiameter / 2, |
| 48 | + endRadius = tipDiameter / 2, |
| 49 | + angle = -atan(segEndY(seg01) / segEndX(seg01)) - (180 / nTeeth), |
| 50 | + reverse = true, |
| 51 | + ) |
| 52 | + // Position the end line of the sketch at the start of the next tooth |
| 53 | + |> line(endAbsolute = polar(angle = 360 / nTeeth, length = baseDiameter / 2)) |
| 54 | + // Pattern the sketch about the center by the specified number of teeth, then close the sketch |
| 55 | + |> patternCircular2d( |
| 56 | + %, |
| 57 | + instances = nTeeth, |
| 58 | + center = [0, 0], |
| 59 | + arcDegrees = 360, |
| 60 | + rotateDuplicates = true, |
| 61 | + ) |
| 62 | + |> close() |
| 63 | + // Subtract the keyway sketch from the gear sketch |
| 64 | + |> subtract2d(tool = holeWithKeyway) |
| 65 | + // Extrude the gear to the specified height |
| 66 | + |> extrude(length = gearHeight) |
57 | 67 |
|
58 |
| -// Extrude the gear body |
59 |
| -body = startSketchOn(XY) |
60 |
| - |> circle(center = [0, 0], radius = baseDiameter / 2) |
61 |
| - |> extrude(length = gearHeight) |
62 |
| - |
63 |
| -toothAngle = 360 / nTeeth / 1.5 |
64 |
| - |
65 |
| -// Plot the involute curve |
66 |
| -fn leftInvolute(@i, accum) { |
67 |
| - j = 100 - i // iterate backwards |
68 |
| - return line(accum, endAbsolute = [xs[j], ys[j]]) |
69 |
| -} |
70 |
| - |
71 |
| -fn rightInvolute(@i, accum) { |
72 |
| - x = rs[i] * cos(-toothAngle + units::toDegrees(atan(ys[i] / xs[i]))) |
73 |
| - y = -rs[i] * sin(-toothAngle + units::toDegrees(atan(ys[i] / xs[i]))) |
74 |
| - return line(accum, endAbsolute = [x, y]) |
| 68 | + return gearSketch |
75 | 69 | }
|
76 | 70 |
|
77 |
| -// Draw gear teeth |
78 |
| -start = startSketchOn(XY) |
79 |
| - |> startProfile(at = [xs[101], ys[101]]) |
80 |
| -teeth = reduce([0..100], initial = start, f = leftInvolute) |
81 |
| - |> arc(angleStart = 0, angleEnd = toothAngle, radius = baseDiameter / 2) |
82 |
| - |> reduce([1..101], initial = %, f = rightInvolute) |
83 |
| - |> close() |
84 |
| - |> extrude(length = gearHeight) |
85 |
| - |> patternCircular3d( |
86 |
| - axis = [0, 0, 1], |
87 |
| - center = [0, 0, 0], |
88 |
| - instances = nTeeth, |
89 |
| - arcDegrees = 360, |
90 |
| - rotateDuplicates = true, |
91 |
| - ) |
92 |
| - |
93 |
| -// Define the constants of the keyway and the bore hole |
94 |
| -keywayWidth = 0.250 |
95 |
| -keywayDepth = keywayWidth / 2 |
96 |
| -holeDiam = 2 |
97 |
| -holeRadius = 1 |
98 |
| -startAngle = asin(keywayWidth / 2 / holeRadius) |
| 71 | +spurGear( |
| 72 | + nTeeth = 21, |
| 73 | + module = 1.5, |
| 74 | + pressureAngle = 14, |
| 75 | + gearHeight = 6, |
| 76 | +) |
99 | 77 |
|
100 |
| -// Sketch the keyway and center hole and extrude |
101 |
| -keyWay = startSketchOn(body, face = END) |
102 |
| - |> startProfile(at = [ |
103 |
| - holeRadius * cos(startAngle), |
104 |
| - holeRadius * sin(startAngle) |
105 |
| - ]) |
106 |
| - |> xLine(length = keywayDepth) |
107 |
| - |> yLine(length = -keywayWidth) |
108 |
| - |> xLine(length = -keywayDepth) |
109 |
| - |> arc(angleStart = -1 * units::toDegrees(startAngle) + 360, angleEnd = 180, radius = holeRadius) |
110 |
| - |> arc(angleStart = 180, angleEnd = units::toDegrees(startAngle), radius = holeRadius) |
111 |
| - |> close() |
112 |
| - |> extrude(length = -gearHeight) |
0 commit comments