kcl-samples → gear →
gear
KCL
// 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.
// Define constants
const gearRadius = 2 // inches
const nTeeth = 8
const width = 2 // inches
// Create a function for sketch of a single tooth
fn tooth = () => {
const toothSketch = startSketchOn('XY')
|> startProfileAt([0, gearRadius], %)
|> arc({
angleStart: 90,
angleEnd: 90 - (180 / pi() * asin(0.7376425 / gearRadius)),
radius: gearRadius
}, %, $base)
|> angledLine({
angle: 180 - (180 / pi() * asin(0.7376425 / gearRadius)),
length: 0.0001
}, %)
|> tangentialArc({
offset: -70 + 180 / pi() * asin(0.7376425 / gearRadius),
radius: 0.389854023
}, %, $philly)
|> line([-0.329118, 0.904244], %)
|> tangentialArcTo([
lastSegX(%) - 0.157636,
lastSegY(%) + 0.110378
], %, $corner)
|> xLineTo(0, %)
|> xLineTo(-1 * segEndX(corner), %)
|> tangentialArcTo([
lastSegX(%) - 0.157636,
lastSegY(%) - 0.110378
], %)
|> lineTo([-1 * segEndX(philly), segEndY(philly)], %, $tag2)
|> tangentialArcTo([-1 * segEndX(base), segEndY(base)], %)
|> arc({
angleEnd: 90,
angleStart: 90 + 180 / pi() * asin(0.7376425 / gearRadius),
radius: gearRadius
}, %)
|> close(%)
|> extrude(width, %)
return [toothSketch]
}
// Create the body
const body = startSketchOn('XY')
|> circle([0, 0], gearRadius, %)
|> extrude(width, %)
// Pattern the teeth around the body
const teeth = tooth()
|> patternCircular3d({
arcDegrees: 360,
axis: [0, 0, 1],
center: [0, 0, 0],
repetitions: nTeeth - 1,
rotateDuplicates: true
}, %)
// Define the constants of the keyway and the bore hole
const keywayWidth = 0.250
const keywayDepth = keywayWidth/2
const holeDiam = 2
const holeRadius = 1
const startAngle = asin(keywayWidth/2/holeRadius)
// sketch the keyway and center hole and extrude
const sketch001 = startSketchOn(body, 'END')
|> startProfileAt([holeRadius*cos(startAngle), holeRadius*sin(startAngle)], %)
|> xLine(keywayDepth, %)
|> yLine(-keywayWidth,%)
|> xLine(-keywayDepth,%)
|> arc({
angleEnd: 180,
angleStart: -1*180/pi()*startAngle+360,
radius: holeRadius,
}, %)
|> arc({
angleEnd: 180/pi()*startAngle,
angleStart: 180,
radius: holeRadius,
}, %)
|> close(%)
|> extrude(-width, %)