# No. 25, Bevel-gears (Brown 1868): "Those of equal diameters are termed 'miter-gears'."
#
# Plate: two equal miter gears, 30 teeth, shafts at right angles. The upper gear sits on a vertical
# shaft and its toothed band opens downwards; the other sits on a horizontal lay shaft and its band
# opens to the right; the two pitch cones meet at their common apex between them, so the toothed
# bands cross in the middle of the picture (the plate shows exactly that crossing).
#
# Layout (cm, as picked off the plate at round numbers): apex at the origin; each gear 30 teeth at
# pitch radius 6 (module 0.4), 45 deg cones so a miter pair, face width 3. The top gear's heel (back
# disc) is at z = +6, radius 6, shaft up from the disc to z = 11.6 with a collar behind the gear; the
# lay gear's heel at x = -6 its shaft out to x = -12.6, collar at its end.
#
# Only the vertical shaft is motor-driven; the lay shaft turns ONLY through bevel tooth contact
# (one convex hull per tooth, src/geom/bevel.ts), as on No. 7.
number: 25
slug: bevel-gears
name: Bevel-gears
brown: "Those of equal diameters are termed \u2018miter-gears.\u2019"
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 80
  duration_s: 5
  solver: PGS          # tooth contacts are not convex (No. 7's train)
  multiccd: true
  floor: false         # the shafts are carried in bearings, not standing on the ground
bodies:
  - {id: upright, shape: assembly, pos: [0, 0, 0], color: "#e2d8bf"}   # vertical shaft; its gear's apex at the origin
  - {id: lay, shape: assembly, pos: [0, 0, 0], color: "#d9cfb6"}      # lay shaft, gear apex at the origin too
joints:
  - {id: j_up, type: hinge, body: upright, axis: [0, 0, 1], damping: 0.005}
  - {id: j_lay, type: hinge, body: lay, axis: [1, 0, 0], damping: 0.005}
bevels:
  # 45 deg pitch cones, equal on both gears: a miter pair. Phase 0 on both meshes them tooth into
  # space at the start (a scan of the lay gear's phase: 0 -> no contact; half a pitch, as on No. 7's
  # train, started the teeth 5.2 mm into each other).
  - {id: gTop, body: upright, teeth: 30, pitch_radius: 6, cone_angle: 0.7853982, face_width: 3, backlash: 0.04, phase: 0, quat: [0.7071068, 0.7071068, 0, 0]}
  - {id: gLay, body: lay, teeth: 30, pitch_radius: 6, cone_angle: 0.7853982, face_width: 3, backlash: 0.04, phase: 0, quat: [0.7071068, 0, 0, 0.7071068]}
shafts:
  # the shaft is visual only: bearings carry it, only the teeth collide
  - {id: sh_up, body: upright, from: [0, 0, 5.6], to: [0, 0, 11.6], radius: 0.55}
  - {id: sh_up_collar, body: upright, from: [0, 0, 6.1], to: [0, 0, 7.6], radius: 0.95}
  - {id: sh_lay, body: lay, from: [-5.6, 0, 0], to: [-12.6, 0, 0], radius: 0.55}
  - {id: sh_lay_collar, body: lay, from: [-11.2, 0, 0], to: [-12.6, 0, 0], radius: 0.95}
contact: {solref: [0.0008, 1], solimp: [0.95, 0.99, 0.001], margin: 0}   # heavy band: a stiffer contact than No. 1
driver: {joint: j_up, kind: velocity, rpm: 30, kv: 2, max_torque: 5}
checks:
  # Miter gears, equal tooth counts (30 and 30): the lay shaft turns exactly as fast as the upright
  # shaft, the same sense as driven teeth cross (both axes right-handed at 90 deg). Expect
  # omega_lay / omega_up = z_up/z_lay = 30/30 = 1.
  - {type: ratio, out: j_lay, in: j_up, expect: 1, tol: 0.02, settle_s: 2, window_s: 1}
  # The gear roots and the shaft hubs must not foul where the two pitch cones touch: penetration
  # across all contacts stays a few hundredths of a millimetre.
  - {type: penetration, max: 0.0008, settle_s: 2}
camera: {target: [-3, 0, 2], position: [-1, -52, 17], fov: 30}   # front view as in the plate: lay shaft to the left, upright shaft up
display:
  output: j_lay
  labels: {j_up: "Upright shaft (driver)", j_lay: "Lay shaft, driven only by the teeth"}
  expect: {default: 1}
  proof: {label: "Teeth out of contact", sub: "the miter gears stop touching: the lay shaft stops"}
