# No. 55 (Brown 1868): "Different velocity given to two gears, A and C, on the same shaft, by the
# pinion, B."
#
# As drawn (cm; the drawing plane is x-z, depth y): the spur gear A (16 teeth) and the internal gear C
# (36) turn on the same shaft line, A fast on the shaft and C loose on it with its own hub; the pinion
# B (10), the one motor-driven shaft, stands between them at 10.4 from the axis and gears with both
# (ZC = ZA + 2 ZB, so one centre distance serves both). No. 34's straight-flanked teeth, module 0.8.
# B turns A the other way at 10/16 of its speed and C its own way at 10/36: two speeds, and
# two senses, on the one shaft line. Generator: opencode-runs/batch7/gen055.py.
number: 55
slug: different-velocity-two-gears
name: Different velocity given to two gears on the same shaft
brown: "Different velocity given to two gears, A and C, on the same shaft, by the pinion, B."
units: cm
sim:
  timestep: 0.0002
  integrator: implicitfast
  iterations: 100
  solver: PGS   # CG blows up at the first tooth contacts (B wedged between A and C)
  multiccd: true
  duration_s: 6
  floor: false
bodies:
  - id: gearC
    shape: part
    pos: [0, 0, 0]
    density: 7800
    friction: 0.1
    color: "#e8dec6"
    pieces:
      - {kind: band, center: [0, 0], r: [15.3, 16.8], a: [0, 6.2831853], y: [-0.8, 0.8]}   # the rim
      - {kind: disc, center: [0, 0], radius: 16.8, inner: 1.6, y: [0.8, 1.4]}   # the web behind
      - {kind: disc, center: [0, 0], radius: 1.6, inner: 0.6, y: [0.8, 3.0]}                     # its hub, loose on the shaft
      - {kind: disc, center: [0, 11.5], radius: 1.2, y: [0.78, 0.8], color: "#b9ab8e"}   # bosses on the web (show it turning)
      - {kind: disc, center: [0, -11.5], radius: 1.2, y: [0.78, 0.8], color: "#b9ab8e"}
      - {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}
      - {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}
  - id: shaft
    shape: part
    pos: [0, 0, 0]
    density: 7800
    friction: 0.1
    color: "#e4d9bf"
    pieces:
      - {kind: rod, from: [0, -4.5, 0], to: [0, 4.5, 0], radius: 0.6, color: "#8f8a80"}   # the shaft
      - {kind: disc, center: [0, 0], radius: 5.55, inner: 0.6, y: [-0.8, 0.8]}   # A's body, fast on it
      - {kind: disc, center: [0, 3.2], radius: 0.8, y: [-0.82, -0.8], color: "#b9ab8e"}
      - {kind: poly, points: [[-5.6571, -0.2646], [-5.3277, -1.9204], [-6.7582, -1.7002], [-6.8944, -1.0154]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-5.1252, -2.4094], [-4.1873, -3.813], [-5.5931, -4.157], [-5.981, -3.5765]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-3.813, -4.1873], [-2.4094, -5.1252], [-3.5765, -5.981], [-4.157, -5.5931]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-1.9204, -5.3277], [-0.2646, -5.6571], [-1.0154, -6.8944], [-1.7002, -6.7582]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[0.2646, -5.6571], [1.9204, -5.3277], [1.7002, -6.7582], [1.0154, -6.8944]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[2.4094, -5.1252], [3.813, -4.1873], [4.157, -5.5931], [3.5765, -5.981]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[4.1873, -3.813], [5.1252, -2.4094], [5.981, -3.5765], [5.5931, -4.157]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[5.3277, -1.9204], [5.6571, -0.2646], [6.8944, -1.0154], [6.7582, -1.7002]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[5.6571, 0.2646], [5.3277, 1.9204], [6.7582, 1.7002], [6.8944, 1.0154]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[5.1252, 2.4094], [4.1873, 3.813], [5.5931, 4.157], [5.981, 3.5765]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[3.813, 4.1873], [2.4094, 5.1252], [3.5765, 5.981], [4.157, 5.5931]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[1.9204, 5.3277], [0.2646, 5.6571], [1.0154, 6.8944], [1.7002, 6.7582]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-0.2646, 5.6571], [-1.9204, 5.3277], [-1.7002, 6.7582], [-1.0154, 6.8944]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-2.4094, 5.1252], [-3.813, 4.1873], [-4.157, 5.5931], [-3.5765, 5.981]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-4.1873, 3.813], [-5.1252, 2.4094], [-5.981, 3.5765], [-5.5931, 4.157]], y: [-0.8, 0.8], collide: 1}
      - {kind: poly, points: [[-5.3277, 1.9204], [-5.6571, 0.2646], [-6.8944, 1.0154], [-6.7582, 1.7002]], y: [-0.8, 0.8], collide: 1}
  - id: pinion
    shape: part
    pos: [-10.4, 0, 0]
    density: 7800
    friction: 0.1
    color: "#d8ceba"
    pieces:
      - {kind: disc, center: [-10.4, 0], radius: 3.15, y: [-0.8, 0.8]}
      - {kind: rod, from: [-10.4, -8.6, 0], to: [-10.4, 0.7, 0], radius: 0.5, color: "#8f8a80"}   # its shaft, out to the front
      - {kind: disc, center: [-10.4, 0], radius: 3.6, y: [-7.3, -5.3], color: "#9c958a"}   # its driving pulley (inertia for the velocity drive)
      - {kind: poly, points: [[-7.2, -0.5027], [-7.2, 0.5027], [-6.4, 0.5278], [-5.84, 0.324], [-5.84, -0.324], [-6.4, -0.5278]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-7.5157, 1.4743], [-8.1066, 2.2876], [-7.4742, 2.7781], [-6.9013, 2.9424], [-6.5205, 2.4182], [-6.8537, 1.9242]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-8.9331, 2.8881], [-9.8892, 3.1987], [-9.6659, 3.9673], [-9.299, 4.4369], [-8.6828, 4.2367], [-8.662, 3.6411]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-10.9108, 3.1987], [-11.8669, 2.8881], [-12.138, 3.6411], [-12.1172, 4.2367], [-11.501, 4.4369], [-11.1341, 3.9673]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-12.6934, 2.2876], [-13.2843, 1.4743], [-13.9463, 1.9242], [-14.2795, 2.4182], [-13.8987, 2.9424], [-13.3258, 2.7781]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-13.6, 0.5027], [-13.6, -0.5027], [-14.4, -0.5278], [-14.96, -0.324], [-14.96, 0.324], [-14.4, 0.5278]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-13.2843, -1.4743], [-12.6934, -2.2876], [-13.3258, -2.7781], [-13.8987, -2.9424], [-14.2795, -2.4182], [-13.9463, -1.9242]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-11.8669, -2.8881], [-10.9108, -3.1987], [-11.1341, -3.9673], [-11.501, -4.4369], [-12.1172, -4.2367], [-12.138, -3.6411]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-9.8892, -3.1987], [-8.9331, -2.8881], [-8.662, -3.6411], [-8.6828, -4.2367], [-9.299, -4.4369], [-9.6659, -3.9673]], y: [-0.8, 0.8], collide: 2}
      - {kind: poly, points: [[-8.1066, -2.2876], [-7.5157, -1.4743], [-6.8537, -1.9242], [-6.5205, -2.4182], [-6.9013, -2.9424], [-7.4742, -2.7781]], y: [-0.8, 0.8], collide: 2}
  - id: frame
    shape: part
    pos: [0, 0, 0]
    fixed: true
    color: "#cfc6b4"
    pieces:
      - {kind: poly, points: [[-1.5, -20], [1.5, -20], [1.0, 0], [-1.0, 0]], y: [4.5, 5.5]}   # the standard behind, for the shaft
      - {kind: disc, center: [0, 0], radius: 1.3, y: [4.5, 5.5]}
      - {kind: poly, points: [[-11.9, -20], [-8.9, -20], [-9.4, 0], [-11.4, 0]], y: [-8.6, -7.6]}   # and in front, for B's
      - {kind: disc, center: [-10.4, 0], radius: 1.3, y: [-8.6, -7.6]}
      - {kind: poly, points: [[-1.5, -20], [1.5, -20], [1.0, 0], [-1.0, 0]], y: [-5.5, -4.5]}   # and for the shaft's front end
      - {kind: disc, center: [0, 0], radius: 1.3, y: [-5.5, -4.5]}
      - {kind: poly, points: [[-16, -21], [6, -21], [6, -20], [-16, -20]], y: [-10, 7], color: "#b9b09c"}
joints:
  - {id: j_B, type: hinge, body: pinion, axis: [0, 1, 0], damping: 0.001}
  - {id: j_A, type: hinge, body: shaft, axis: [0, 1, 0], damping: 0.05}
  - {id: j_C, type: hinge, body: gearC, axis: [0, 1, 0], damping: 0.05}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_B, kind: velocity, rpm: 30, kv: 2, max_torque: 6}
checks:
  - {type: ratio, out: j_A, in: j_B, expect: -0.625, tol: 0.004, settle_s: 0.5, window_s: 5.5}
  - {type: ratio, out: j_C, in: j_B, expect: 0.2778, tol: 0.004, settle_s: 0.5, window_s: 5.5}
  - {type: penetration, max: 0.001, settle_s: 0.5}
camera: {target: [-3, 0, -5], position: [-50, -80, 22], fov: 36}
display:
  output: j_C
  labels: {j_B: "Pinion B (driver, 10 teeth)", j_A: "Gear A on the shaft (16)", j_C: "Internal gear C, loose on the shaft (36)"}
  proof: {label: "A's teeth out of contact", sub: "B still turns C, but A and its shaft stand"}
