1- @settings(defaultLengthUnit = in)
21// Spur Gear
32// 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.
43
4+ // Set units
5+ @settings(defaultLengthUnit = in)
56
6- // Set Units
7-
8-
9- // Define constants
7+ // Define parameters
108nTeeth = 21
119module = 0.5
1210pitchDiameter = module * nTeeth
1311pressureAngle = 20
1412addendum = module
1513deddendum = 1.25 * module
16- baseDiameter = pitchDiameter * cos(toRadians(pressureAngle))
14+ baseDiameter = pitchDiameter * cos(units:: toRadians(pressureAngle))
1715tipDiameter = pitchDiameter + 2 * module
1816gearHeight = 3
1917
2018// Interpolate points along the involute curve
2119cmo = 101
22- rs = map([0..cmo], fn(i) {
23- return baseDiameter / 2 + i / cmo * (tipDiameter - baseDiameter) / 2
24- })
20+ rs = map(
21+ [0..cmo],
22+ f = fn(i) {
23+ return baseDiameter / 2 + i / cmo * (tipDiameter - baseDiameter) / 2
24+ },
25+ )
2526
2627// Calculate operating pressure angle
27- angles = map(rs, fn(r) {
28- return toDegrees( acos(baseDiameter / 2 / r))
29- })
28+ angles = map(
29+ rs,
30+ f = fn(r) {
31+ return units::toDegrees( acos(baseDiameter / 2 / r))
32+ },
33+ )
3034
3135// Calculate the involute function
32- invas = map(angles, fn(a) {
33- return tan(toRadians(a)) - toRadians(a)
34- })
36+ invas = map(
37+ angles,
38+ f = fn(a) {
39+ return tan(units::toRadians(a)) - units::toRadians(a)
40+ },
41+ )
3542
3643// Map the involute curve
37- xs = map([0..cmo], fn(i) {
38- return rs[i] * cos(invas[i])
39- })
40-
41- ys = map([0..cmo], fn(i) {
42- return rs[i] * sin(invas[i])
43- })
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+ )
4457
4558// Extrude the gear body
46- body = startSketchOn('XY' )
59+ body = startSketchOn(XY )
4760 |> circle(center = [0, 0], radius = baseDiameter / 2)
4861 |> extrude(length = gearHeight)
4962
@@ -56,21 +69,17 @@ fn leftInvolute(i, sg) {
5669}
5770
5871fn rightInvolute(i, sg) {
59- x = rs[i] * cos(toRadians(-toothAngle + toDegrees(atan(ys[i] / xs[i]))))
60- y = -rs[i] * sin(toRadians(-toothAngle + toDegrees(atan(ys[i] / xs[i]))))
72+ x = rs[i] * cos(units:: toRadians(-toothAngle + units:: toDegrees(atan(ys[i] / xs[i]))))
73+ y = -rs[i] * sin(units:: toRadians(-toothAngle + units:: toDegrees(atan(ys[i] / xs[i]))))
6174 return line(sg, endAbsolute = [x, y])
6275}
6376
6477// Draw gear teeth
65- start = startSketchOn('XY')
66- |> startProfileAt([xs[101], ys[101]], %)
67- teeth = reduce([0..100], start, leftInvolute)
68- |> arc({
69- angleStart = 0,
70- angleEnd = toothAngle,
71- radius = baseDiameter / 2
72- }, %)
73- |> reduce([1..101], %, rightInvolute)
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)
7483 |> close()
7584 |> extrude(length = gearHeight)
7685 |> patternCircular3d(
@@ -89,23 +98,15 @@ holeRadius = 1
8998startAngle = asin(keywayWidth / 2 / holeRadius)
9099
91100// Sketch the keyway and center hole and extrude
92- keyWay = startSketchOn(body, face = ' END' )
93- |> startProfileAt( [
101+ keyWay = startSketchOn(body, face = END)
102+ |> startProfile(at = [
94103 holeRadius * cos(startAngle),
95104 holeRadius * sin(startAngle)
96- ], % )
105+ ])
97106 |> xLine(length = keywayDepth)
98107 |> yLine(length = -keywayWidth)
99108 |> xLine(length = -keywayDepth)
100- |> arc({
101- angleEnd = 180,
102- angleStart = -1 * 180 / PI * startAngle + 360,
103- radius = holeRadius
104- }, %)
105- |> arc({
106- angleEnd = 180 / PI * startAngle,
107- angleStart = 180,
108- radius = holeRadius
109- }, %)
109+ |> arc(angleStart = -1 * units::toDegrees(startAngle) + 360, angleEnd = 180, radius = holeRadius)
110+ |> arc(angleStart = 180, angleEnd = units::toDegrees(startAngle), radius = holeRadius)
110111 |> close()
111112 |> extrude(length = -gearHeight)
0 commit comments