2025-03-06 18:01:24 -05:00
// Spur Gear
// 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.
2025-04-04 11:03:13 -07:00
// Set units
2025-03-06 18:01:24 -05:00
@settings(defaultLengthUnit = in)
2025-04-04 11:03:13 -07:00
// Define parameters
2025-03-06 18:01:24 -05:00
nTeeth = 21
module = 0.5
pitchDiameter = module * nTeeth
pressureAngle = 20
addendum = module
deddendum = 1.25 * module
2025-04-30 11:07:05 -04:00
baseDiameter = pitchDiameter * cos(pressureAngle)
2025-03-06 18:01:24 -05:00
tipDiameter = pitchDiameter + 2 * module
gearHeight = 3
// Interpolate points along the involute curve
cmo = 101
2025-04-25 19:09:03 -05:00
rs = map(
[0..cmo],
f = fn(i) {
return baseDiameter / 2 + i / cmo * (tipDiameter - baseDiameter) / 2
},
)
2025-03-06 18:01:24 -05:00
// Calculate operating pressure angle
2025-04-25 19:09:03 -05:00
angles = map(
rs,
f = fn(r) {
2025-04-30 11:07:05 -04:00
return units::toDegrees( acos(baseDiameter / 2 / r))
2025-04-25 19:09:03 -05:00
},
)
2025-03-06 18:01:24 -05:00
// Calculate the involute function
2025-04-25 19:09:03 -05:00
invas = map(
angles,
f = fn(a) {
2025-04-30 11:07:05 -04:00
return tan(a) - units::toRadians(a)
2025-04-25 19:09:03 -05:00
},
)
2025-03-06 18:01:24 -05:00
// Map the involute curve
2025-04-25 19:09:03 -05:00
xs = map(
[0..cmo],
f = fn(i) {
2025-04-30 11:07:05 -04:00
return rs[i] * cos(invas[i]: number(rad))
2025-04-25 19:09:03 -05:00
},
)
2025-03-06 18:01:24 -05:00
2025-04-25 19:09:03 -05:00
ys = map(
[0..cmo],
f = fn(i) {
2025-04-30 11:07:05 -04:00
return rs[i] * sin(invas[i]: number(rad))
2025-04-25 19:09:03 -05:00
},
)
2025-03-06 18:01:24 -05:00
// Extrude the gear body
2025-03-26 08:53:34 -07:00
body = startSketchOn(XY)
|> circle(center = [0, 0], radius = baseDiameter / 2)
2025-03-06 18:01:24 -05:00
|> extrude(length = gearHeight)
toothAngle = 360 / nTeeth / 1.5
// Plot the involute curve
fn leftInvolute(i, sg) {
j = 100 - i // iterate backwards
return line(sg, endAbsolute = [xs[j], ys[j]])
}
fn rightInvolute(i, sg) {
2025-04-30 11:07:05 -04:00
x = rs[i] * cos(-toothAngle + units::toDegrees(atan(ys[i] / xs[i])))
y = -rs[i] * sin(-toothAngle + units::toDegrees(atan(ys[i] / xs[i])))
2025-03-06 18:01:24 -05:00
return line(sg, endAbsolute = [x, y])
}
// Draw gear teeth
2025-03-26 08:53:34 -07:00
start = startSketchOn(XY)
2025-04-25 16:01:35 -05:00
|> startProfile(at = [xs[101], ys[101]])
2025-04-25 19:09:03 -05:00
teeth = reduce([0..100], initial = start, f = leftInvolute)
2025-04-18 17:40:44 -05:00
|> arc(angleStart = 0, angleEnd = toothAngle, radius = baseDiameter / 2)
2025-04-25 19:09:03 -05:00
|> reduce([1..101], initial = %, f = rightInvolute)
2025-03-06 18:01:24 -05:00
|> close()
|> extrude(length = gearHeight)
|> patternCircular3d(
axis = [0, 0, 1],
center = [0, 0, 0],
instances = nTeeth,
arcDegrees = 360,
2025-03-26 08:53:34 -07:00
rotateDuplicates = true,
2025-03-06 18:01:24 -05:00
)
// Define the constants of the keyway and the bore hole
keywayWidth = 0.250
keywayDepth = keywayWidth / 2
holeDiam = 2
holeRadius = 1
2025-04-30 11:07:05 -04:00
startAngle = asin(keywayWidth / 2 / holeRadius)
2025-03-06 18:01:24 -05:00
// Sketch the keyway and center hole and extrude
2025-04-14 05:58:19 -04:00
keyWay = startSketchOn(body, face = END)
2025-04-25 16:01:35 -05:00
|> startProfile(at = [
2025-04-30 11:07:05 -04:00
holeRadius * cos(startAngle),
holeRadius * sin(startAngle)
2025-04-25 16:01:35 -05:00
])
2025-03-07 22:07:16 -06:00
|> xLine(length = keywayDepth)
|> yLine(length = -keywayWidth)
|> xLine(length = -keywayDepth)
2025-04-29 08:41:31 +12:00
|> arc(angleStart = -1 * units::toDegrees(startAngle) + 360, angleEnd = 180, radius = holeRadius)
|> arc(angleStart = 180, angleEnd = units::toDegrees(startAngle), radius = holeRadius)
2025-03-06 18:01:24 -05:00
|> close()
|> extrude(length = -gearHeight)