number: 322
slug: triangle-parallel-ruler
name: Triangle Parallel Ruler
brown: "A very convenient construction of parallel ruler for drawing, made by cutting a quadrangle through the diagonal, forming two right-angled triangles, A and B. It is used by sliding the hypotenuse of one triangle upon that of the other."
units: cm
sim: {timestep: 0.0005, integrator: implicitfast, iterations: 50, duration_s: 8, floor: false, gravity: 0}
bodies:
  # the paper, and the triangle B held down on it (the sheet is the frame)
  - id: B
    shape: part
    pos: [0, 0, 0]
    fixed: true
    friction: 0.08
    color: "#d8c9a3"
    pieces:
      - {kind: poly, points: [[-6, -7], [32, -7], [32, 13], [-6, 13]], y: [0.4, 0.5], color: "#f4efe2"}
      - {kind: poly, points: [[0.0000, 0.0000], [24.0000, 0.0000], [24.0000, 8.0000]], y: [-0.3, 0.3], collide: 1}
  # the triangle A on the paper: free to slide either way and to turn, as a loose triangle is
  - {id: Ax, shape: part, pos: [7.9991, 0, 5.3362], mass: 0.02, color: "#8f8a80", pieces: [{kind: disc, center: [7.9991, 5.3362], radius: 0.1, y: [-0.35, -0.3], collide: 0}]}
  - {id: An, shape: part, pos: [7.9991, 0, 5.3362], mount: Ax, mass: 0.02, color: "#8f8a80", pieces: [{kind: disc, center: [7.9991, 5.3362], radius: 0.1, y: [-0.35, -0.3], collide: 0}]}
  - id: A
    shape: part
    pos: [7.9991, 0, 5.3362]
    mount: An
    friction: 0.08
    color: "#c9b68c"
    density: 700
    pieces:
      - {kind: poly, points: [[-0.0009, 0.0028], [-0.0009, 8.0028], [23.9991, 8.0028]], y: [-0.3, 0.3], collide: 2}
      - {kind: disc, center: [7.9991, 5.3362], radius: 0.6, y: [-0.4, -0.3], color: "#8f8a80"}
joints:
  # the hand moves the triangle A to and fro along the paper (the one driven joint)
  - {id: j_x, type: slide, body: Ax, axis: [1, 0, 0], damping: 0.01}
  # the fingers keep it pressed against B's edge: a light spring across the cut
  - {id: j_n, type: slide, body: An, axis: [0.316228, 0, -0.948683], stiffness: 30, springref: 3.0, damping: 0.5, range: [-6, 2.4]}
  - {id: j_rot, type: hinge, body: A, axis: [0, -1, 0], damping: 0.002}
contact: {solref: [0.002, 1.0], solimp: [0.95, 0.99, 0.0005], margin: 0}
driver: {joint: j_x, kind: velocity, rpm: 0, swing: {amplitude: 0.06, hz: 0.25}, kv: 50, max_torque: 20}
checks:
  # Sliding on B's edge, A goes up the cut as it goes along: across the cut it moves -H/W·cos = -0.3162
  # of its travel along the paper (the cut runs 8 up in 24 across), both ways of the stroke.
  - {type: ratio, out: j_n, in: j_x, expect: -0.3162, tol: 0.01, settle_s: 0.5, window_s: 7.0}
  # and it never turns: every edge of A stays parallel to where it started (under 0.1 deg)
  - {type: position, joint: j_rot, min: -0.0017, max: 0.0017, settle_s: 0.2, window_s: 7.5}
  - {type: penetration, max: 0.0003, settle_s: 0.2}
camera: {target: [13, 0, -2], position: [13, -95, -2], fov: 30}
display:
  output: j_n
  labels: {j_x: Hand moving A along the paper (driver), j_n: A across the cut, j_rot: Turn of A}
