// Two meshing spur gears on their shafts, fully parametric:
// change the module or the number of teeth and run the script again
const module = 2 // size of the teeth (mm)
// point (x, y, z) of the frame of 'center', turned by 'angle' (rad) around Z
function Local(center, x, y, z, angle)
{
return new GO2SXYZ(
center.X() + x * Math.cos(angle) - y * Math.sin(angle),
center.Y() + x * Math.sin(angle) + y * Math.cos(angle),
center.Z() + z)
}
// spur gear: body + teeth + hub, minus bore, keyway and lightening holes
function Gear(center, nbTeeth, width, bore, nbHoles, phase, color)
{
const pitch = module * nbTeeth / 2 // pitch radius
const root = pitch - 1.25 * module // root radius
const tip = pitch + module // tip radius
const half = Math.PI * module / 5 // half thickness of a straight tooth
const gear = GO2SSolidCreate.Cylinder(center, root, width)
// one tooth every 360/nbTeeth degrees
const teeth = []
for (let i = 0; i < nbTeeth; i++)
{
const a = phase + 2 * Math.PI * i / nbTeeth
teeth.push(GO2SSolidCreate.Cuboid(
Local(center, root - 1, -half, 0, a),
Local(center, tip, -half, 0, a),
Local(center, tip, half, 0, a),
width))
}
// hub
const hubOrg = Local(center, 0, 0, -5, 0)
teeth.push(GO2SSolidCreate.Cylinder(hubOrg, 2 * bore, width + 10))
gear.MultiUnion(teeth)
// bore with its keyway
const cutOrg = Local(center, 0, 0, -10, 0)
const cuts = [GO2SSolidCreate.Cylinder(cutOrg, bore, width + 20)]
cuts.push(GO2SSolidCreate.Cuboid(
Local(center, 0, -bore / 4, -10, 0),
Local(center, bore + 2, -bore / 4, -10, 0),
Local(center, bore + 2, bore / 4, -10, 0),
width + 20))
// lightening holes between the hub and the teeth
const holeDist = (root + 2 * bore) / 2
const holeRadius = (root - 2 * bore) / 4
for (let i = 0; i < nbHoles; i++)
{
const a = 2 * Math.PI * i / nbHoles
const holeOrg = Local(center, holeDist, 0, -1, a)
cuts.push(GO2SSolidCreate.Cylinder(holeOrg, holeRadius, width + 2))
}
gear.MultiSubtract(cuts)
gear.SetColor(color)
gear.SetName(`Gear Z${nbTeeth}`)
return gear
}
// a big gear and a small one, placed at the right distance to mesh
const z1 = 40, z2 = 20
const c1 = new GO2SXYZ(0, 0, 0)
const c2 = new GO2SXYZ(module * (z1 + z2) / 2, 0, 0)
Gear(c1, z1, 15, 8, 6, 0, 0xC08040)
// the small one is turned by half a tooth to fit between the teeth
Gear(c2, z2, 15, 5, 0, Math.PI + Math.PI / z2, 0x2080E0)
// shafts
for (const [center, radius] of [[c1, 8], [c2, 5]])
{
const shaft = Local(center, 0, 0, -30, 0)
GO2SSolidCreate.Cylinder(shaft, radius, 75).SetColor(0x808080)
}