Models / Morphogen terrain relief

Morphogen terrain relief

Morphogen: a living-looking terrain drawn by a field. Two waves cross in a space that is twisted around an off-centre point and folded by two shears; each layer cuts away where the field rises above a level. Deeper layers use higher levels, so channels narrow and split into pockets towards the backer.

5 parts on 5 sheets, shown together. Each sheet has its own cut file.

Source 175 lines

// Morphogen: a living-looking terrain drawn by a field. Two waves cross in a
// space that is twisted around an off-centre point and folded by two shears;
// each layer cuts away where the field rises above a level. Deeper layers use
// higher levels, so channels narrow and split into pockets towards the backer.
 
/* [Composition] */
// A ready recipe, or custom to use the settings below
preset = "undercurrent"; // [undercurrent:Undercurrent, delta:Delta, cellular:Cellular, custom:Custom]
// All panels, or one panel at a time
output = "all"; // [all:All panels, layer0:Layer 0 (front), layer1:Layer 1, layer2:Layer 2, layer3:Layer 3, layer4:Layer 4, backer:Backer]
// Panel diameter
size = 360; // [340:10:400]
// Spacing of the waves
wavelength = 44; // [40:1:58]
// Up and down position of the twist centre
focus_y = 15; // [-40:5:40]
 
/* [Custom] */
// How far the shears fold the waves
warp = 24; // [15:1:32]
// Twist at the centre, in degrees; negative turns the other way
vortex = 90; // [-100:5:100]
// Shifts where the waves meet, in degrees
phase = 28; // [0:1:180]
// Side to side position of the twist centre
focus_x = -35; // [-50:5:50]
// Field level of the front layer: low for broad channels, high for pockets
threshold = 0.22; // [0.2:0.02:0.7]
// Field level added for each deeper layer
terrace = 0.23; // [0.15:0.01:0.25]
 
/* [Relief] */
// Relief layers, plus the backer
layers = 4; // [3:1:5]
// Rounding of the openings, and the smallest sliver removed
smooth = 2; // [1.5:0.25:3]
 
/* [Material] */
// Sheet thickness
$thickness = 3; // [2:0.5:4]
// Beam width
$kerf = 0.15; // [0:0.01:0.25]
 
/* [Hidden] */
$material = "plywood";
$sheet = [440, 440];
$gap = 6;
$fn = 192;
// Each recipe: [warp, vortex, phase, focus_x, threshold, terrace]
recipes = [
  [24, 90, 28, -35, 0.22, 0.23],
  [32, 35, 110, 25, 0.22, 0.23],
  [20, -65, 65, -35, 0.62, 0.18]
];
keys = ["undercurrent", "delta", "cellular"];
p = preset == "custom" ? [warp, vortex, phase, focus_x, threshold, terrace] : recipes[search(preset, keys)];
fold = p[0];
spin = p[1];
shift = p[2];
fx = p[3];
level = p[4];
step = p[5];
// Grid squares across the panel
N = 120;
R = size / 2;
h = size / N;
 
assert(size >= 340 && size <= 400, "Size: 340 to 400 mm");
assert(wavelength >= 40 && wavelength <= 58, "Wavelength: 40 to 58 mm");
assert(warp >= 15 && warp <= 32, "Warp: 15 to 32 mm");
assert(vortex >= -100 && vortex <= 100, "Vortex: -100 to 100 degrees");
assert(phase >= 0 && phase <= 180, "Phase: 0 to 180 degrees");
assert(focus_x >= -50 && focus_x <= 50 && focus_y >= -40 && focus_y <= 40, "Twist centre: x -50 to 50, y -40 to 40 mm");
assert(threshold >= 0.2 && threshold <= 0.7, "Threshold: 0.2 to 0.7");
assert(terrace >= 0.15 && terrace <= 0.25, "Terrace: 0.15 to 0.25");
assert(layers >= 3 && layers <= 5 && layers == floor(layers), "Layers: a whole number from 3 to 5");
assert(smooth >= 1.5 && smooth <= 3, "Smoothing: 1.5 to 3 mm");
assert($thickness >= 2 && $thickness <= 4 && $kerf >= 0 && $kerf <= 0.25, "Thickness: 2 to 4 mm; kerf: 0 to 0.25 mm");
assert(contains(["all", "layer0", "layer1", "layer2", "layer3", "layer4", "backer"], output), "Unknown output");
assert(output != "layer3" || layers >= 4, "Layer 3 needs four or more layers");
assert(output != "layer4" || layers >= 5, "Layer 4 needs five layers");
 
// A twist that fades with distance from the focus, two sine shears, then a
// main wave crossed by a weaker one and a slight left to right slope
function field(x, y) = let (
  dx = x - fx,
  dy = y - focus_y,
  r = sqrt(dx * dx + dy * dy),
  t = atan2(dy, dx) + spin * exp(-r * r / (0.14 * size * size)),
  xx = r * cos(t) + fx,
  yy = r * sin(t) + focus_y,
  u = xx + fold * sin(yy * 360 / 170 + shift) + 8 * sin(yy * 360 / 65),
  v = yy + 15 * sin(u * 360 / 140),
  a = u * 360 / wavelength,
  b = v * 360 / (wavelength * 1.35))
  sin(a) + 0.55 * cos(b) + 0.10 * x / R;
 
// The field sampled once at every grid point, and the grid points in rows:
// point (i, j) is GP[at(i, j)]
V = [for (j = [0:N]) [for (i = [0:N]) field(-R + i * h, -R + j * h)]];
GP = [for (j = [0:N], i = [0:N]) [-R + i * h, -R + j * h]];
function at(i, j) = j * (N + 1) + i;
// Grid squares that reach into the circle the openings are clipped to
function near(i, j) = let (x = -R + (i + 0.5) * h, y = -R + (j + 0.5) * h) sqrt(x * x + y * y) < R - 16 + h;
 
// Where the field crosses the level between grid points p and q
function cut(p, q, fp, fq, v) = let (s = (v - fp) / (fq - fp)) [p[0] + (q[0] - p[0]) * s, p[1] + (q[1] - p[1]) * s];
// The part above the level of a triangle p, q, r whose corner p is the odd
// one out, always as four points
function corner(p, q, r, fp, fq, fr, v) = let (m = cut(p, q, fp, fq, v), n = cut(r, p, fr, fp, v))
  fp >= v ? [p, m, n, n] : [q, r, n, m];
function piece(a, b, c, fa, fb, fc, v) = let (A = fa >= v, B = fb >= v, C = fc >= v)
  A == B ? corner(c, a, b, fc, fa, fb, v)
  : A == C ? corner(b, c, a, fb, fc, fa, v)
  : corner(a, b, c, fa, fb, fc, v);
 
// Every grid square split into two triangles (k = 0, 1): no ambiguous cases.
// Triangles wholly above the level are outlines through the grid points, the
// ones the level crosses get their own points. All of them tile without
// overlapping, so even-odd polygons of them are their union.
module raw_field(v) {
  F = [for (j = [0:N - 1], i = [0:N - 1], k = [0:1])
    let (bi = i + 1, bj = j + k, ci = i + 1 - k, cj = j + 1)
      if (near(i, j) && V[j][i] >= v && V[bj][bi] >= v && V[cj][ci] >= v) [at(i, j), at(bi, bj), at(ci, cj)]];
  X = [for (j = [0:N - 1], i = [0:N - 1], k = [0:1])
    let (bi = i + 1, bj = j + k, ci = i + 1 - k, cj = j + 1, fa = V[j][i], fb = V[bj][bi], fc = V[cj][ci],
      n = (fa >= v ? 1 : 0) + (fb >= v ? 1 : 0) + (fc >= v ? 1 : 0))
      if (near(i, j) && n > 0 && n < 3) piece(GP[at(i, j)], GP[at(bi, bj)], GP[at(ci, cj)], fa, fb, fc, v)];
  union() {
    if (len(F) > 0) polygon(GP, F);
    if (len(X) > 0) polygon([for (p = X) each p], [for (k = [0:len(X) - 1]) [4 * k, 4 * k + 1, 4 * k + 2, 4 * k + 3]]);
  }
}
 
// Close the seams between triangles, round the tips and drop slivers, then
// close any gaps the rounding left
module holes(z) {
  offset(r = -smooth) offset(r = smooth)
    offset(r = smooth) offset(r = -2 * smooth) offset(r = smooth)
      intersection() {
        circle(r = R - 16);
        raw_field(level + z * step);
      }
}
 
// A round panel with three bolt holes, spaced unevenly so it only fits one way
module blank() {
  difference() {
    circle(r = R);
    for (a = [20, 142, 268]) translate([(R - 8) * cos(a), (R - 8) * sin(a)]) circle(d = 4.5, $fn = 48);
  }
}
 
module panel(z) {
  // Assembled: on the backer, the deepest layer first and layer 0 at the front
  part(str("Layer ", z), at = [0, 0, (layers - z) * $thickness]) difference() {
    blank();
    holes(z);
  }
}
 
function layer_step(z) = str("Lay layer ", z, z == 0 ? " on top" : " on", ", face up");
if (output == "all") {
  // Name the steps in build order first: the backer, then the deepest layer up
  step("Lay the backer down") {}
  for (z = [layers - 1:-1:0]) step(layer_step(z)) {}
  for (z = [0:layers - 1]) step(layer_step(z)) panel(z);
  step("Lay the backer down") part("Backer", at = [0, 0, 0]) blank();
} else if (output == "backer") part("Backer") blank();
else for (z = [0:layers - 1]) if (output == "layer" + str(z)) panel(z);
 
// Assembly: lay the backer down, then the layers from the deepest up to
// layer 0 on top, all face up and none flipped; the uneven bolt holes line
// them up. Join the stack with three M4 bolts, a washer on each side and
// locknuts; five 3 mm panels take M4 x 25 mm bolts.