Coin Sorter Bank
A coin bank that sorts coins by diameter. The leaning front plate carries a sloped rail: a coin stood on the high end leans against the plate and rolls downhill past a row of windows that get taller one by one, and at the first window taller than itself it tips through the plate into the bin behind. A currency parameter selects the coin table (JPY 6 coins, EUR 8 coins, USD 5 coins) with the real diameters and thicknesses, and each window is set between its own coin and the next larger one. The file checks the window order, that every coin rides the rail, falls through its own window and is still held at the window before it, and that each window opens into its own bin. Two parts without supports: the bin box prints upright and the sorter plate flat on its back; the plate stands between the end walls behind a toe lip and lifts out to empty the bins. With yen coins the bank is 212 x 73 x 100 mm assembled and the print plate 212 x 182 x 99 mm; the euro version is 261 mm long. The closest pair of coins (5 and 100 yen, 0.6 mm apart) leaves 0.3 mm each way, so print the plate accurately. Rail slope, plate lean, window margins, plate and wall thickness, fit and the engraved value labels are parameters.
# Coin Sorter Bank - coins roll down a sloped rail and drop through graded windows into one bin each
#
# How it works: the sorter plate is the leaning front wall of the bank. A coin
# stood on the rail at the high end leans back against the plate and rolls
# downhill. Above the rail the plate has one window per coin, the lowest
# window first and each one a little taller than the last. As long as a coin
# is taller than a window its top edge is still held by the plate above the
# window (the lintel), so it rolls across; at the first window taller than
# itself nothing holds its top, it tips backwards through the plate and
# falls into the bin behind that window. Coins are therefore sorted by
# diameter, smallest first.
#
# Two parts, both printed as laid out on the plate, no supports:
# - the bin box, upright: floor, back wall, end walls and one partition per
# window; the front edges of the partitions lean back by `lean`.
# - the sorter plate, flat on its back, rail upwards.
# Assembly: stand the plate between the end walls, bottom edge behind the toe
# lip, leaning back on the partitions. Lift it out to empty the bins.
#
# Coin tables (diameter x thickness in mm, sorted by diameter):
# JPY: 1 yen 20.0 x 1.5, 50 yen 21.0 x 1.7, 5 yen 22.0 x 1.5,
# 100 yen 22.6 x 1.7, 10 yen 23.5 x 1.5, 500 yen 26.5 x 1.8
# EUR: 1 c 16.25 x 1.67, 2 c 18.75 x 1.67, 10 c 19.75 x 1.93, 5 c 21.25 x 1.67,
# 20 c 22.25 x 2.14, 1 euro 23.25 x 2.33, 50 c 24.25 x 2.38, 2 euro 25.75 x 2.20
# USD: dime 17.91 x 1.35, cent 19.05 x 1.52, nickel 21.21 x 1.95,
# quarter 24.26 x 1.75, dollar coin 26.49 x 2.00
@param choices:["JPY", "EUR", "USD"] group:"Coins" desc:"Currency: sets the coin diameters, thicknesses and labels"
$currency = "JPY"
@param choices:["print", "assembled"] group:"Output" desc:"Print plate, or the plate standing in the box"
$view = "print"
@param 10..20 step:1 group:"Sorter" desc:"Slope of the rail (deg)"
$slope = 15
@param 10..35 step:1 group:"Sorter" desc:"Lean of the plate back from vertical (deg)"
$lean = 20
@param 0.5..1.5 step:0.1 group:"Sorter" desc:"Largest window height over its coin (mm); never more than half the step to the next coin"
$pass_max = 1.0
@param 2..6 step:0.5 group:"Sorter" desc:"Window length over the coin diameter (mm)"
$slot_margin = 3.0
@param 3..8 step:0.5 group:"Sorter" desc:"Pillar between two windows (mm)"
$pillar = 4.0
@param 2.4..4 step:0.2 group:"Sorter" desc:"Plate thickness (mm)"
$plate_t = 3.0
@param group:"Sorter" desc:"Engrave the coin value above each window"
$labels = true
@param 1.6..3 step:0.2 group:"Box" desc:"Box wall and floor thickness (mm)"
$wall = 2.0
@param 0.2..0.5 step:0.05 group:"Box" desc:"Clearance of the plate between the end walls and behind the toe lip (mm)"
$fit = 0.3
# --- Coin tables -------------------------------------------------------------
$dia = if $currency == "JPY" then [20.0, 21.0, 22.0, 22.6, 23.5, 26.5] else (if $currency == "EUR" then [16.25, 18.75, 19.75, 21.25, 22.25, 23.25, 24.25, 25.75] else [17.91, 19.05, 21.21, 24.26, 26.49])
$thk = if $currency == "JPY" then [1.5, 1.7, 1.5, 1.7, 1.5, 1.8] else (if $currency == "EUR" then [1.67, 1.67, 1.93, 1.67, 2.14, 2.33, 2.38, 2.20] else [1.35, 1.52, 1.95, 1.75, 2.00])
$name = if $currency == "JPY" then ["1", "50", "5", "100", "10", "500"] else (if $currency == "EUR" then ["1c", "2c", "10c", "5c", "20c", "1E", "50c", "2E"] else ["10c", "1c", "5c", "25c", "100c"])
$n = len($dia)
assert len($thk) == $n
assert len($name) == $n
def dmax(i) = if i == 0 then $dia[0] else max($dia[i], dmax(i - 1))
def tmax(i) = if i == 0 then $thk[0] else max($thk[i], tmax(i - 1))
$d_max = dmax($n - 1)
$t_max = tmax($n - 1)
# --- Windows -----------------------------------------------------------------
# Window i is $hgt(i) tall, measured square to the rail: more than its own
# coin, less than the next coin. The step between two neighbouring coins is
# shared half and half, so the tightest pair of the table sets the print
# accuracy that is needed (JPY: 5 yen and 100 yen are 0.6 mm apart).
def pass(i) = if i == $n - 1 then $pass_max else min($pass_max, ($dia[i + 1] - $dia[i]) / 2)
def hgt(i) = $dia[i] + pass(i)
def wlen(i) = $dia[i] + $slot_margin
$entry = $d_max + 3 # plain plate at the high end to set a coin on
$tail = 4
def wx(i) = if i == 0 then $entry else wx(i - 1) + wlen(i - 1) + $pillar
$pl = wx($n - 1) + wlen($n - 1) + $tail # plate length
# slot order: diameters and window heights strictly rising along the rail,
# every window above its own coin and below the next one
def sorted(i) = if i >= $n - 1 then true else ($dia[i + 1] > $dia[i] and hgt(i + 1) > hgt(i) and wx(i + 1) > wx(i) + wlen(i) and sorted(i + 1))
def graded(i) = if i >= $n - 1 then true else (hgt(i) - $dia[i] >= 0.25 and $dia[i + 1] - hgt(i) >= 0.25 and graded(i + 1))
assert sorted(0)
assert graded(0)
assert hgt($n - 1) > $d_max
# --- Plate, in its print frame: X along the plate, Y up the plate, Z out of the front
$cs = cos($slope)
$sn = sin($slope)
$tn = tan($slope)
$v_lo = 10 # rail above the plate bottom at the low end
$rail_t = 3 # rail thickness, square to its top
$rail_w = $t_max + 1.2 # rail stands this far out of the plate
$band = 9 # lintel above the tallest window
def rail(x) = $v_lo + ($pl - x) * $tn # rail top at x
$ph = rail(0) + hgt($n - 1) / $cs + $band # plate height
$blank = box $pl $ph $plate_t | translate ($pl / 2) ($ph / 2) ($plate_t / 2)
def win(i) = polyline [(wx(i), rail(wx(i))), (wx(i) + wlen(i), rail(wx(i) + wlen(i))), (wx(i) + wlen(i), rail(wx(i) + wlen(i)) + hgt(i) / $cs), (wx(i), rail(wx(i)) + hgt(i) / $cs)] | extrude ($plate_t + 2) | translate 0 0 -1
$wins = union [win(i) for i in range($n)]
$rail_rib = polyline [(0, rail(0)), ($pl, rail($pl)), ($pl, rail($pl) - $rail_t / $cs), (0, rail(0) - $rail_t / $cs)] | extrude ($plate_t + $rail_w)
$stop = box 2 11 ($plate_t + $rail_w) | translate ($pl - 1) ($v_lo + 2.5) (($plate_t + $rail_w) / 2) # end stop of the rail
$plate0 = $blank + $rail_rib + $stop - $wins
# labels: engraved 0.6 mm above each window, parallel to the rail
$ts = 8
def lab0(i) = text $name[i] $ts | extrude 1
def lab(i) = lab0(i) | translate (-lab0(i).bbox.center[0]) (-lab0(i).bbox.center[1]) 0 | rotate 0 0 (-$slope) | translate (wx(i) + wlen(i) / 2) (rail(wx(i) + wlen(i) / 2) + hgt(i) / $cs + $band / 2) ($plate_t - 0.6)
$labs = union [lab(i) for i in range($n)]
$plate = if $labels then ($plate0 - $labs) else $plate0
assert $plate.solids == 1
assert $plate.bbox.x ~ $pl tol:0.01
assert $plate.bbox.y ~ $ph tol:0.01
assert $plate.bbox.z ~ ($plate_t + $rail_w) tol:0.01
assert $pillar >= 3
assert $band >= 6
# --- Each coin passes only its own window -----------------------------------
# Coin i stands on the rail over the middle of window j, 0.05 mm clear of
# rail and plate. riding: it is free there and carried by the rail.
# through: the same disc pushed through the plate; free only if the window
# is taller than the coin.
$eps = 0.05
def cxr(i, j) = wx(j) + wlen(j) / 2 - ($dia[i] / 2 + $eps) * $sn # point of the rail under the coin
def ccx(i, j) = wx(j) + wlen(j) / 2
def ccy(i, j, lift) = rail(cxr(i, j)) + ($dia[i] / 2 + lift) * $cs
def riding(i, j, lift) = cylinder ($dia[i] / 2) $thk[i] | translate ccx(i, j) ccy(i, j, lift) ($plate_t + $eps + $thk[i] / 2)
def through(i, j) = cylinder ($dia[i] / 2) ($plate_t + 2) | translate ccx(i, j) ccy(i, j, $eps) ($plate_t / 2)
def rides(i, j) = clear($plate0, riding(i, j, $eps)) and clear($plate0, riding(i, j, -0.3)) == false
def falls(i) = clear($plate0, through(i, i))
def held(i) = if i == 0 then true else (rides(i, i - 1) and clear($plate0, through(i, i - 1)) == false)
def held_early(i, j) = if j < 0 then true else (hgt(j) < $dia[i] and held_early(i, j - 1))
def coins_ok(i) = if i >= $n then true else (rides(i, i) and falls(i) and held(i) and held_early(i, i - 1) and coins_ok(i + 1))
assert coins_ok(0)
# the entry: the largest coin stands on the rail in front of the first window
$c_in = cylinder ($d_max / 2) $t_max | translate ($entry / 2) (rail($entry / 2 - ($d_max / 2 + $eps) * $sn) + ($d_max / 2 + $eps) * $cs) ($plate_t + $eps + $t_max / 2)
assert clear($plate0, $c_in)
assert $c_in.bbox.min[0] >= 0
assert $c_in.bbox.max[0] <= $entry
# --- Bin box, upright: X along the plate, Y to the back, Z up ---------------
# The lean plane passes through Y = 0 at the top of the floor; the back of the
# plate lies on it.
$cl = cos($lean)
$tl = tan($lean)
$lip_w = 2
$lip_h = 4
$part_t = 1.6
$bh = $wall + $ph * $cl # box height = top of the plate
$y_f = -$plate_t * $cl - $fit - $lip_w # front of the floor: the toe lip stands $fit in front of the plate's front bottom edge
assert $lip_h >= $plate_t * sin($lean) + 1.5
$y_b = $ph * sin($lean) + $d_max + 4 + $wall # back of the box
def lean_y(z) = (z - $wall) * $tl
def cheek_y(z) = lean_y(z) - ($plate_t + 2) / $cl
def prism(pts, x0, len) = polyline pts | extrude len | rotate 90 0 0 | rotate 0 0 90 | translate x0 0 0
$bx0 = -$fit - $wall # box from here ...
$bx1 = $pl + $fit + $wall # ... to here in X
$floor = prism([($y_f, 0), ($y_b, 0), ($y_b, $wall), ($y_f, $wall)], $bx0, $bx1 - $bx0)
$toe = prism([($y_f, 0), ($y_f + $lip_w, 0), ($y_f + $lip_w, $wall + $lip_h), ($y_f, $wall + $lip_h)], $bx0, $bx1 - $bx0)
$back = prism([($y_b - $wall, 0), ($y_b, 0), ($y_b, $bh), ($y_b - $wall, $bh)], $bx0, $bx1 - $bx0)
$end_pts = [($y_f, 0), ($y_b, 0), ($y_b, $bh), (cheek_y($bh), $bh), (cheek_y($wall + $lip_h), $wall + $lip_h), ($y_f, $wall + $lip_h)]
$end_l = prism($end_pts, $bx0, $wall)
$end_r = prism($end_pts, $bx1 - $wall, $wall)
$part_pts = [(0, 0), ($y_b, 0), ($y_b, $bh), (lean_y($bh), $bh), (0, $wall)]
def part_x(i) = wx(i) - $pillar / 2 # partition i stands behind the pillar before window i
def part(i) = prism($part_pts, part_x(i + 1) - $part_t / 2, $part_t)
$parts = union [part(i) for i in range($n - 1)]
$box = $floor + $toe + $back + $end_l + $end_r + $parts
assert $box.solids == 1
assert $box.bbox.x ~ ($bx1 - $bx0) tol:0.01
assert $box.bbox.y ~ ($y_b - $y_f) tol:0.01
assert $box.bbox.z ~ $bh tol:0.01
assert $box.bbox.min[2] ~ 0 tol:0.001
assert $part_t <= $pillar - 2 # a partition hides behind its pillar, clear of both windows
assert cheek_y($wall + $lip_h) >= $y_f
# --- Plate standing in the box ----------------------------------------------
# 0.1 mm off the partitions and the floor, so the two parts stay separate
# solids in the assembled view.
$g = 0.1
def stand(s) = s | rotate (90 - $lean) 0 0 | translate 0 (-$g * $cl) ($wall + $g)
$plate_up = stand($plate)
assert clear($plate_up, $box)
assert clear($plate_up | translate 0 0.4 0, $box) == false # it leans on the partitions
assert clear($plate_up | translate 0 (-$fit - 0.4) 0, $box) == false # the toe lip holds its foot
assert clear($plate_up | translate ($fit + 0.2) 0 0, $box) == false # the end walls hold it sideways
# coin i, pushed through its window, is over bin i: between its two partitions
def bin_ok(i) = if i >= $n then true else (ccx(i, i) - $dia[i] / 2 > part_x(i) + $part_t / 2 and (if i == $n - 1 then true else ccx(i, i) + $dia[i] / 2 < part_x(i + 1) - $part_t / 2) and bin_ok(i + 1))
assert bin_ok(0)
# the bin behind the plate is deep enough for the coin to turn over
assert $y_b - $wall - lean_y($bh) >= $d_max + 3
print "coins" $n "plate" $pl "x" $ph "box height" $bh "depth" ($y_b - $y_f)
print "window heights" [hgt(i) for i in range($n)]
print "pass margin, smallest" [pass(i) for i in range($n)]
# --- Layout -----------------------------------------------------------------
$plate_flat = $plate | translate 0 ($y_f - 6 - $ph) 0
assert clear($plate_flat, $box)
$assembled = union [$box, $plate_up]
$printed = union [$box, $plate_flat]
assert $printed.solids == 2
assert if $view == "assembled" then $assembled.solids == 2 else true
if $view == "assembled" then $assembled else $printed