Straight-Line Linkage
A desk model of the Peaucellier-Lipkin cell, the seven-bar linkage that turns the swing of a crank into an exact straight line. Two long bars and a rhombus make the tracing point the geometric inverse of the crank pin, and because the crank pin moves on a circle through the centre of inversion, the tracing point moves along a straight line, which is engraved on the base with a tick every 15 degrees of crank angle. Every joint position is solved in the code from the bar lengths alone, and the tracing point is asserted to stay on the line at seven crank angles; a parameter sets the crank angle shown in the assembled view, and bars sharing a level are checked not to collide over the +-60 degree stroke. Assembled it is about 99 x 110 x 20.5 mm with a 93.5 mm stroke; the print plate is 187 x 110 x 20.5 mm. Eleven parts, no hardware: base, crank and six more bars on four levels with printed pins, and three press-on caps, all printed flat without supports. Parameters: crank length, long bar length, rhombus side, bar width and thickness, pin diameter and fit.
# Straight-Line Linkage - desk model of the Peaucellier-Lipkin cell, seven bars that draw an exact straight line
#
# Two long bars run from the fixed pivot O to the corners B and D of a rhombus A-B-P-D.
# Whatever the shape of the rhombus, O, A and P stay in line and OA x OP = long^2 - side^2:
# P is the inversion of A. A crank of length |OQ| on the second fixed pivot Q carries A
# round a circle through O, and the inverse of a circle through the centre of inversion
# is a straight line, so P moves along x = (long^2 - side^2) / (2 crank), exactly.
# The base has that line engraved with a tick every 15 deg of crank angle, and the bar at
# P carries a pointer pin that runs just above it.
# The position of every joint is solved from the bar lengths alone (two circle
# intersections and the rhombus), and P is asserted to be on the line at seven angles.
#
# Eleven printed parts, no hardware: base, crank, two long bars, two pin bars, one plain
# short bar, the pointer bar and three press-on caps. The bars sit on four levels so that
# no two bars on the same level ever meet. Everything prints flat without supports, pins
# up (the pointer bar is printed upside down, as laid out).
# Assembly, from the base up: the crank on Q; the two pin bars, one with its hole on the
# crank pin at A, the other as the opposite side D-P; the plain short bar A-D and a long
# bar O-B; the second long bar O-D and the pointer bar B-P on top, its pin down through
# the hole at P; caps on O, B and D.
@param choices:["print", "assembled"] desc:"Print layout or assembled view"
$view = "print"
@param -60..60 step:5 desc:"Assembled view: crank angle (deg, 0 = crank pointing away from O)"
$angle = 25
@param 20..30 step:1 group:"Linkage" desc:"Crank length = distance between the fixed pivots O and Q (mm)"
$crank = 24
@param 60..90 step:1 group:"Linkage" desc:"Long bars O-B and O-D (mm)"
$long = 72
@param 30..45 step:1 group:"Linkage" desc:"Side of the rhombus (mm)"
$side = 36
@param 9..12 step:0.5 group:"Bars" desc:"Width of the bars (mm)"
$bar_w = 10
@param 2.4..4 step:0.2 group:"Bars" desc:"Thickness of the bars (mm)"
$t = 3
@param 4..6 step:0.5 group:"Bars" desc:"Pin diameter (mm)"
$pin_d = 5
@param 0.15..0.35 step:0.05 group:"Print" desc:"Clearance of the pins in their holes, per side (mm)"
$fit = 0.2
$a_max = 60 # the linkage is checked for crank angles of +-60 deg
$k2 = $long ** 2 - $side ** 2 # the constant of the inversion
$line_x = $k2 / (2 * $crank) # where the straight line is
# the bars can reach: at the ends of the stroke A is still further from O than long - side,
# and P no further than long + side
assert 2 * $crank * cos($a_max / 2) > $long - $side + 1
assert $line_x / cos($a_max / 2) < $long + $side - 1
# --- solving the linkage from the bar lengths ---------------------------------------------
# intersection of two circles, on the left of the line from (pu,pv) to (qu,qv)
def ccd($pu, $pv, $qu, $qv) = sqrt(($qu - $pu) ** 2 + ($qv - $pv) ** 2)
def ccx($pu, $pv, $r1, $qu, $qv, $r2) = (ccd($pu, $pv, $qu, $qv) ** 2 + $r1 ** 2 - $r2 ** 2) / (2 * ccd($pu, $pv, $qu, $qv))
def cch($pu, $pv, $r1, $qu, $qv, $r2) = sqrt(max(0, $r1 ** 2 - ccx($pu, $pv, $r1, $qu, $qv, $r2) ** 2))
def ccu($pu, $pv, $r1, $qu, $qv, $r2) = $pu + (ccx($pu, $pv, $r1, $qu, $qv, $r2) * ($qu - $pu) - cch($pu, $pv, $r1, $qu, $qv, $r2) * ($qv - $pv)) / ccd($pu, $pv, $qu, $qv)
def ccv($pu, $pv, $r1, $qu, $qv, $r2) = $pv + (ccx($pu, $pv, $r1, $qu, $qv, $r2) * ($qv - $pv) + cch($pu, $pv, $r1, $qu, $qv, $r2) * ($qu - $pu)) / ccd($pu, $pv, $qu, $qv)
# O = (0, 0), Q = (crank, 0); A on the crank, B and D from the long bars and the rhombus sides
def ax($a) = $crank + $crank * cos($a)
def ay($a) = $crank * sin($a)
def bx($a) = ccu(0, 0, $long, ax($a), ay($a), $side)
def by($a) = ccv(0, 0, $long, ax($a), ay($a), $side)
def dx($a) = ccu(ax($a), ay($a), $side, 0, 0, $long)
def dy($a) = ccv(ax($a), ay($a), $side, 0, 0, $long)
def px($a) = bx($a) + dx($a) - ax($a) # P closes the rhombus
def py($a) = by($a) + dy($a) - ay($a)
# the tracing point is on the line at every angle, and moves along it as the half-angle tangent
assert abs(px(-60) - $line_x) < 0.000001
assert abs(px(-40) - $line_x) < 0.000001
assert abs(px(-20) - $line_x) < 0.000001
assert abs(px(0) - $line_x) < 0.000001
assert abs(px(20) - $line_x) < 0.000001
assert abs(px(40) - $line_x) < 0.000001
assert abs(px(60) - $line_x) < 0.000001
assert abs(px($angle) - $line_x) < 0.000001
assert abs(py(40) - $line_x * tan(20)) < 0.000001
assert abs(py(-60) + $line_x * tan(30)) < 0.000001
assert abs(py(0)) < 0.000001
# the bars keep their lengths in the solved position
assert abs(sqrt((px(40) - bx(40)) ** 2 + (py(40) - by(40)) ** 2) - $side) < 0.000001
assert abs(sqrt(dx(40) ** 2 + dy(40) ** 2) - $long) < 0.000001
# the rhombus stays open at the ends of the stroke: half its B-D diagonal
$half_bd = sqrt((bx($a_max) - dx($a_max)) ** 2 + (by($a_max) - dy($a_max)) ** 2) / 2
assert $half_bd >= $bar_w + 2
$stroke = 2 * $line_x * tan($a_max / 2)
# --- levels -----------------------------------------------------------------------------
$base_t = 4
$lev = $t + 0.3 # level pitch: bar thickness + 0.3 mm of air
$z1 = $base_t + 0.3 # level 1: crank
$z2 = $z1 + $lev # level 2: the two pin bars (A-B and D-P)
$z3 = $z2 + $lev # level 3: long bar O-B and short bar A-D
$z4 = $z3 + $lev # level 4: long bar O-D and pointer bar B-P
$cap_h = 3
$z_cap = $z4 + $t + 0.3
$r_e = $bar_w / 2
$r_p = $pin_d / 2
$r_h = $r_p + $fit
def strip($len) = wire [(0, 0), ($len, 0)] | offset $r_e | extrude $t
def eye($x) = cylinder $r_h ($t + 2) center:(true, true, false) | translate $x 0 (-1)
def holes2($len) = union [eye(0), eye($len)]
def peg($x, $z0, $z1) = cylinder $r_p ($z1 - $z0) center:(true, true, false) | translate $x 0 $z0
# plain bar: a hole at each end
def plain($len) = strip($len) - holes2($len)
$bar_long = plain($long)
$bar_short = plain($side)
# pin bar: hole at 0, pin at the far end up through two more levels and a cap
$pinbar0 = union [strip($side), peg($side, 0, $z_cap + $cap_h - $z2)]
$pinbar = $pinbar0 - eye(0)
# crank: hole at Q, pin at A up through levels 2 and 3, flush with the top of level 3
$crank0 = union [strip($crank), peg($crank, 0, $z3 + $t - $z1)]
$crankbar = $crank0 - eye(0)
# pointer bar (as assembled): hole at B, pin at P down to 0.6 mm above the base
$point0 = union [strip($side), peg($side, -($z4 - $base_t - 0.6), 0.5)]
$pointbar = $point0 - eye(0)
$cap0 = cylinder $r_e $cap_h center:(true, true, false)
$cap = $cap0 - (cylinder ($r_p + 0.05) ($cap_h + 2) center:(true, true, false) | translate 0 0 (-1))
assert $pinbar.solids == 1
assert $crankbar.solids == 1
assert $pointbar.solids == 1
# base: a T with the fixed pivots on the stem and the engraved line on the cross bar
$half_y = $stroke / 2 + 8
$stem = box ($line_x + $r_e + 3) (2 * $r_e + 6) $base_t center:(false, true, false) | translate (-$r_e - 3) 0 0
$cross = box 20 (2 * $half_y) $base_t center:(true, true, false) | translate $line_x 0 0
$o_post = cylinder $r_e ($z3 - 0.3 - $base_t + 0.5) center:(true, true, false) | translate 0 0 ($base_t - 0.5)
$o_pin = cylinder $r_p ($z_cap + $cap_h - $base_t) center:(true, true, false) | translate 0 0 $base_t
$q_pin = cylinder $r_p ($z1 + $t - $base_t + 0.5) center:(true, true, false) | translate $crank 0 ($base_t - 0.5)
$groove = box 0.8 ($stroke + 6) 1 center:(true, true, false) | translate $line_x 0 ($base_t - 0.6)
def tick($i) = box 7 0.6 1 center:(true, true, false) | translate $line_x ($line_x * tan(($i - 4) * 7.5)) ($base_t - 0.6)
$ticks = union [tick($i) for $i in range(9)]
$base0 = union [$stem, $cross, $o_post, $o_pin, $q_pin]
$marks = union [$groove, $ticks]
$base = $base0 - $marks
assert $base.solids == 1
# --- the linkage at crank angle $a ---------------------------------------------------------
def dir($x0, $y0, $x1, $y1) = atan2($y1 - $y0, $x1 - $x0)
def lay($s, $x, $y, $ang, $z) = $s | rotate 0 0 $ang | translate $x $y $z
def m_crank($a) = lay($crankbar, $crank, 0, $a, $z1)
def m_ab($a) = lay($pinbar, ax($a), ay($a), dir(ax($a), ay($a), bx($a), by($a)), $z2)
def m_pd($a) = lay($pinbar, px($a), py($a), dir(px($a), py($a), dx($a), dy($a)), $z2)
def m_ad($a) = lay($bar_short, ax($a), ay($a), dir(ax($a), ay($a), dx($a), dy($a)), $z3)
def m_ob($a) = lay($bar_long, 0, 0, dir(0, 0, bx($a), by($a)), $z3)
def m_od($a) = lay($bar_long, 0, 0, dir(0, 0, dx($a), dy($a)), $z4)
def m_bp($a) = lay($pointbar, bx($a), by($a), dir(bx($a), by($a), px($a), py($a)), $z4)
def m_caps($a) = union [$cap | translate 0 0 $z_cap, $cap | translate bx($a) by($a) $z_cap, $cap | translate dx($a) dy($a) $z_cap]
def low($a) = union [$base, m_crank($a)] # base and level 1
def mid($a) = union [m_ab($a), m_pd($a)] # level 2
def top($a) = union [m_bp($a), m_od($a), m_caps($a)] # level 4 and caps
# bars that share a level never meet, and nothing meets the level below or above it
def pose_ok($a) = clear(m_ab($a), m_pd($a)) and clear(m_ad($a), m_ob($a)) and clear(m_od($a), m_bp($a)) and clear($base, m_crank($a)) and clear(low($a), mid($a)) and clear(low($a), m_ad($a)) and clear(low($a), m_ob($a)) and clear(low($a), top($a)) and clear(mid($a), m_ad($a)) and clear(mid($a), m_ob($a)) and clear(mid($a), top($a)) and clear(m_ad($a), top($a)) and clear(m_ob($a), top($a))
assert pose_ok(-$a_max)
assert pose_ok(-$a_max / 2)
assert pose_ok(0)
assert pose_ok($a_max / 2)
assert pose_ok($a_max)
$asm = union [$base, m_crank($angle), m_ab($angle), m_pd($angle), m_ad($angle), m_ob($angle), m_od($angle), m_bp($angle), m_caps($angle)]
assert $asm.solids == 11
# the pointer pin of the built model stands on the engraved line
$tip = m_bp($angle) * (box 400 400 2 center:(true, true, false) | translate 0 0 ($base_t + 0.5))
assert abs($tip.bbox.center[0] - $line_x) < 0.001
assert abs($tip.bbox.center[1] - $line_x * tan($angle / 2)) < 0.001
# --- print layout ---------------------------------------------------------------------------
def put($s, $x, $y) = $s | translate ($x - $s.bbox.min[0]) ($y - $s.bbox.min[1]) (-$s.bbox.min[2])
$x0 = $line_x + 16
$y0 = -$half_y
$row = $bar_w + 3
$point_flip = $pointbar | rotate 180 0 0
$plate = union [$base, put($bar_long, $x0, $y0), put($bar_long, $x0, $y0 + $row), put($pinbar, $x0, $y0 + 2 * $row), put($pinbar, $x0, $y0 + 3 * $row), put($bar_short, $x0, $y0 + 4 * $row), put($point_flip, $x0, $y0 + 5 * $row), put($crankbar, $x0, $y0 + 6 * $row), put($cap, $x0 + $crank + $bar_w + 4, $y0 + 6 * $row), put($cap, $x0 + $crank + 2 * $bar_w + 8, $y0 + 6 * $row), put($cap, $x0 + $crank + 3 * $bar_w + 12, $y0 + 6 * $row)]
assert $plate.solids == 11
assert clear($base, put($bar_long, $x0, $y0))
assert $plate.bbox.min[2] ~ 0 tol:0.001
assert put($point_flip, 0, 0).bbox.z ~ $z4 - $base_t - 0.6 + $t tol:0.01
print "line at x (mm)" $line_x "stroke for +-60 deg (mm)" $stroke
print "shown: crank angle (deg)" $angle "P (mm)" px($angle) py($angle)
print "stack height (mm)" ($z_cap + $cap_h)
$out = if $view == "assembled" then $asm else $plate
$out