# No. 34, An internally toothed spur-gear and pinion (Brown 1868).
#
# "An internally toothed spur-gear and pinion. With ordinary spur-gears (such as represented in 24)
#  the direction of rotation is opposite; but with the internally toothed gear, the two rotate in
#  the same direction; and with the same strength of tooth the gears are capable of transmitting
#  greater force, because more teeth are engaged."
#
# Laid out as in the plate (1 unit = 1 cm; the drawing plane is x-z, depth is y): a ring of 36
# internal teeth (module 0.8, pitch radius 14.4) on a back web and hub, and inside it a 16-tooth
# pinion (pitch radius 6.4) on its own shaft 8.0 below the ring's centre. Straight-flanked teeth
# (20 deg), each its own convex piece (generator: opencode-runs/batch7/gen034.py).
#
# Fully physical. Only the pinion's shaft is motor-driven. The ring turns by tooth contact alone,
# the SAME way as the pinion, at +16/36 = +0.444 of its speed.
number: 34
slug: internal-spur-gear-and-pinion
name: An internally toothed spur-gear and pinion
brown: "An internally toothed spur-gear and pinion. With ordinary spur-gears (such as represented in 24) the direction of rotation is opposite; but with the internally toothed gear, the two rotate in the same direction; and with the same strength of tooth the gears are capable of transmitting greater force, because more teeth are engaged."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: CG
  multiccd: true
  duration_s: 6
  floor: false
bodies:
  - id: ring
    shape: part
    pos: [0, 0, 0]
    density: 7800
    friction: 0.1
    color: "#e8dec6"
    pieces:
      - {kind: band, center: [0, 0], r: [15.1, 16.6], a: [0, 6.2831853], y: [-0.8, 0.8], collide: 0}   # the rim
      - {kind: disc, center: [0, 0], radius: 16.6, inner: 3.0, y: [0.8, 1.4], collide: 0}              # the web behind
      - {kind: disc, center: [0, 0], radius: 3.0, y: [-0.4, 2.2], collide: 0}                           # the hub
      - {kind: disc, center: [0, 11], radius: 1.6, y: [0.78, 0.8], collide: 0, color: "#b9ab8e"}   # a boss on the web (shows it turning)
      - {kind: disc, center: [11, 0], radius: 1.6, y: [0.78, 0.8], collide: 0, color: "#b9ab8e"}   # a boss on the web (shows it turning)
      - {kind: disc, center: [0, -11], radius: 1.6, y: [0.78, 0.8], collide: 0, color: "#b9ab8e"}   # a boss on the web (shows it turning)
      - {kind: disc, center: [-11, 0], radius: 1.6, y: [0.78, 0.8], collide: 0, color: "#b9ab8e"}   # a boss on the web (shows it turning)
      - {kind: poly, points: [[0.8585, -13.8178], [1.554, -13.7569], [2.1657, -15.0686], [0.4839, -15.2157]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[3.2449, -13.4588], [3.9193, -13.2781], [4.7494, -14.4636], [3.1187, -14.9005]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[5.5326, -12.6908], [6.1654, -12.3958], [7.1888, -13.4191], [5.6588, -14.1326]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[7.6523, -11.5373], [8.2243, -11.1368], [9.4098, -11.967], [8.0269, -12.9353]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[9.5395, -10.0332], [10.0332, -9.5395], [11.3449, -10.1512], [10.1512, -11.3449]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[11.1368, -8.2243], [11.5373, -7.6523], [12.9353, -8.0269], [11.967, -9.4098]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[12.3958, -6.1654], [12.6908, -5.5326], [14.1326, -5.6588], [13.4191, -7.1888]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[13.2781, -3.9193], [13.4588, -3.2449], [14.9005, -3.1187], [14.4636, -4.7494]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[13.7569, -1.554], [13.8178, -0.8585], [15.2157, -0.4839], [15.0686, -2.1657]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[13.8178, 0.8585], [13.7569, 1.554], [15.0686, 2.1657], [15.2157, 0.4839]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[13.4588, 3.2449], [13.2781, 3.9193], [14.4636, 4.7494], [14.9005, 3.1187]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[12.6908, 5.5326], [12.3958, 6.1654], [13.4191, 7.1888], [14.1326, 5.6588]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[11.5373, 7.6523], [11.1368, 8.2243], [11.967, 9.4098], [12.9353, 8.0269]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[10.0332, 9.5395], [9.5395, 10.0332], [10.1512, 11.3449], [11.3449, 10.1512]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[8.2243, 11.1368], [7.6523, 11.5373], [8.0269, 12.9353], [9.4098, 11.967]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[6.1654, 12.3958], [5.5326, 12.6908], [5.6588, 14.1326], [7.1888, 13.4191]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[3.9193, 13.2781], [3.2449, 13.4588], [3.1187, 14.9005], [4.7494, 14.4636]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[1.554, 13.7569], [0.8585, 13.8178], [0.4839, 15.2157], [2.1657, 15.0686]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-0.8585, 13.8178], [-1.554, 13.7569], [-2.1657, 15.0686], [-0.4839, 15.2157]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-3.2449, 13.4588], [-3.9193, 13.2781], [-4.7494, 14.4636], [-3.1187, 14.9005]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-5.5326, 12.6908], [-6.1654, 12.3958], [-7.1888, 13.4191], [-5.6588, 14.1326]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-7.6523, 11.5373], [-8.2243, 11.1368], [-9.4098, 11.967], [-8.0269, 12.9353]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-9.5395, 10.0332], [-10.0332, 9.5395], [-11.3449, 10.1512], [-10.1512, 11.3449]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-11.1368, 8.2243], [-11.5373, 7.6523], [-12.9353, 8.0269], [-11.967, 9.4098]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-12.3958, 6.1654], [-12.6908, 5.5326], [-14.1326, 5.6588], [-13.4191, 7.1888]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-13.2781, 3.9193], [-13.4588, 3.2449], [-14.9005, 3.1187], [-14.4636, 4.7494]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-13.7569, 1.554], [-13.8178, 0.8585], [-15.2157, 0.4839], [-15.0686, 2.1657]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-13.8178, -0.8585], [-13.7569, -1.554], [-15.0686, -2.1657], [-15.2157, -0.4839]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-13.4588, -3.2449], [-13.2781, -3.9193], [-14.4636, -4.7494], [-14.9005, -3.1187]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-12.6908, -5.5326], [-12.3958, -6.1654], [-13.4191, -7.1888], [-14.1326, -5.6588]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-11.5373, -7.6523], [-11.1368, -8.2243], [-11.967, -9.4098], [-12.9353, -8.0269]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-10.0332, -9.5395], [-9.5395, -10.0332], [-10.1512, -11.3449], [-11.3449, -10.1512]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-8.2243, -11.1368], [-7.6523, -11.5373], [-8.0269, -12.9353], [-9.4098, -11.967]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-6.1654, -12.3958], [-5.5326, -12.6908], [-5.6588, -14.1326], [-7.1888, -13.4191]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-3.9193, -13.2781], [-3.2449, -13.4588], [-3.1187, -14.9005], [-4.7494, -14.4636]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-1.554, -13.7569], [-0.8585, -13.8178], [-0.4839, -15.2157], [-2.1657, -15.0686]], y: [-0.8, 0.8], collide: 1}
  - id: pinion
    shape: part
    pos: [0, 0, -8]
    density: 7800
    friction: 0.1
    color: "#e4d9bf"
    pieces:
      - {kind: disc, center: [0, -8], radius: 5.7, y: [-0.8, 0.8], collide: 0}     # the pinion's body
      - {kind: rod, from: [0, -5, -8], to: [0, 0.7, -8], radius: 0.7, collide: 0}  # its shaft, out to the front
      - {kind: poly, points: [[-0.8441, -13.6], [0.8441, -13.6], [0.3491, -14.96], [-0.3491, -14.96]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[1.3632, -13.4967], [2.9229, -12.8507], [2.986, -14.2966], [2.341, -14.5638]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[3.3629, -12.5567], [4.5567, -11.3629], [5.1683, -12.6746], [4.6746, -13.1683]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[4.8507, -10.9229], [5.4967, -9.3632], [6.5638, -10.341], [6.2966, -10.986]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[5.6, -8.8441], [5.6, -7.1559], [6.96, -7.6509], [6.96, -8.3491]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[5.4967, -6.6368], [4.8507, -5.0771], [6.2966, -5.014], [6.5638, -5.659]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[4.5567, -4.6371], [3.3629, -3.4433], [4.6746, -2.8317], [5.1683, -3.3254]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[2.9229, -3.1493], [1.3632, -2.5033], [2.341, -1.4362], [2.986, -1.7034]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[0.8441, -2.4], [-0.8441, -2.4], [-0.3491, -1.04], [0.3491, -1.04]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-1.3632, -2.5033], [-2.9229, -3.1493], [-2.986, -1.7034], [-2.341, -1.4362]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-3.3629, -3.4433], [-4.5567, -4.6371], [-5.1683, -3.3254], [-4.6746, -2.8317]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-4.8507, -5.0771], [-5.4967, -6.6368], [-6.5638, -5.659], [-6.2966, -5.014]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-5.6, -7.1559], [-5.6, -8.8441], [-6.96, -8.3491], [-6.96, -7.6509]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-5.4967, -9.3632], [-4.8507, -10.9229], [-6.2966, -10.986], [-6.5638, -10.341]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-4.5567, -11.3629], [-3.3629, -12.5567], [-4.6746, -13.1683], [-5.1683, -12.6746]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-2.9229, -12.8507], [-1.3632, -13.4967], [-2.341, -14.5638], [-2.986, -14.2966]], y: [-0.8, 0.8], collide: 2}
  - {id: stubs, shape: frame, rods: [{from: [0, 2.2, 0], to: [0, 4.5, 0], radius: 0.8}, {from: [0, -5.6, -8], to: [0, -5.0, -8], radius: 1.0}], color: "#8f8a80"}
joints:
  - {id: j_pinion, type: hinge, body: pinion, axis: [0, 1, 0], damping: 0.001}
  - {id: j_ring, type: hinge, body: ring, axis: [0, 1, 0], damping: 0.02}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_pinion, kind: velocity, rpm: 30, kv: 4, max_torque: 6}
checks:
  - {type: ratio, out: j_ring, in: j_pinion, expect: 0.44444, tol: 0.004, settle_s: 1, window_s: 4}
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [0, 0, -3.5], position: [0, -88, -1], fov: 34}
display:
  output: j_ring
  labels: {j_pinion: "Pinion (driver, 16 teeth)", j_ring: "Internal gear (36 teeth)"}
  proof: {label: "Teeth out of contact", sub: "the pinion turns alone: the ring stands still"}
