| # Y adapter for a dust extraction hose, built from patch() surfaces.
|
| #
|
| # round inlet -> transition to a wide rounded rectangle
|
| # -> crotch: ONE patch with two holes (the branch roots)
|
| # -> two rectangular branches with different size and angle
|
| #
|
| # rotate_extrude() can't do it (no symmetry), hull() would fill the crotch,
|
| # a loft can't branch. The part is hollow with a real wall: the inner skin
|
| # is built the same way, and the openings are closed with flat rims.
|
| from pythonscad import *
|
| import math
|
|
|
| inlet_d = add_parameter("inlet_d", 72, range=[40, 100], step=1, group="Inlet")
|
| wall = add_parameter("wall", 2.5, range=[1.2, 5], step=0.1, group="Inlet")
|
| a_angle = add_parameter("a_angle", 25, range=[0, 45], step=1, group="Branch A")
|
| a_w = add_parameter("a_w", 50, range=[30, 60], step=1, group="Branch A")
|
| a_h = add_parameter("a_h", 34, range=[20, 40], step=1, group="Branch A")
|
| b_angle = add_parameter("b_angle", 20, range=[0, 45], step=1, group="Branch B")
|
| b_w = add_parameter("b_w", 40, range=[25, 55], step=1, group="Branch B")
|
| b_h = add_parameter("b_h", 28, range=[15, 36], step=1, group="Branch B")
|
|
|
| N = 64 # points per outline
|
|
|
|
|
| # ---------------------------------------------------------------- outlines
|
| def rrect(a, b, n):
|
| """Superellipse with half sizes a, b: n=2 circle, n=8 rounded rectangle."""
|
| pts = []
|
| for i in range(N):
|
| t = 2 * math.pi * i / N
|
| c, s = math.cos(t), math.sin(t)
|
| pts.append([math.copysign(abs(c) ** (2 / n), c),
|
| math.copysign(abs(s) ** (2 / n), s)])
|
| return polygon(pts).scale([a, b])
|
|
|
|
|
| def axis(angle):
|
| """Direction of a branch tilted by angle (degrees) around y."""
|
| return [math.sin(math.radians(angle)), 0, math.cos(math.radians(angle))]
|
|
|
|
|
| def at(c, angle, d=0):
|
| """Point d mm along a branch that starts at c."""
|
| return [ci + d * ai for ci, ai in zip(c, axis(angle))]
|
|
|
|
|
| # ---------------------------------------------------------------- patches
|
| def sweep(a, b, c, angle):
|
| """Skin from outline a to outline b; a is centred at c, and the
|
| path runs along axis(angle). The projection puts a outside, b inside."""
|
| d = axis(angle)
|
| u = [d[2], 0, -d[0]] # perpendicular to d, in xz
|
| v = [0, 1, 0]
|
|
|
| def proj(p):
|
| q = [pi - ci for pi, ci in zip(p, c)]
|
| h = sum(x * y for x, y in zip(q, d))
|
| ang = math.atan2(sum(x * y for x, y in zip(q, v)),
|
| sum(x * y for x, y in zip(q, u)))
|
| return [(300 - h) * math.cos(ang), (300 - h) * math.sin(ang)]
|
| return patch(a, holes=[b], proj=proj, grid_spacing_uv=4)
|
|
|
|
|
| def chain(outlines, centres, angle):
|
| return [sweep(a, b, c, angle)
|
| for a, b, c in zip(outlines, outlines[1:], centres)]
|
|
|
|
|
| def top_view(outer, holes):
|
| """Patch whose outlines are nested when seen from above."""
|
| return patch(outer, holes=holes, proj=lambda p: [p[0], p[1]],
|
| grid_spacing_uv=3)
|
|
|
|
|
| def rim(outer, inner, c, angle):
|
| """Flat ring that closes the wall at an opening."""
|
| d = axis(angle)
|
| u = [d[2], 0, -d[0]]
|
| return patch(outer, holes=[inner], proj=lambda p: [
|
| sum((pi - ci) * ui for pi, ci, ui in zip(p, c, u)), p[1]])
|
|
|
|
|
| # ---------------------------------------------------------------- layout
|
| R = inlet_d / 2
|
| Z_COLLAR, Z_TRANS = 25, 62
|
| TRANS = (R + 22, R + 4) # half sizes of the wide transition
|
| A = [-0.44 * TRANS[0], 0, Z_TRANS + 22] # root centre of branch A
|
| B = [0.48 * TRANS[0], 0, Z_TRANS + 18] # root centre of branch B
|
|
|
|
|
| def skin(off):
|
| """One skin of the adapter; off = 0 outside, off = wall inside.
|
| Returns the patches and the outlines at the three openings."""
|
| # inlet: round collar, then a smooth blend into the wide transition
|
| z_in = [0, Z_COLLAR]
|
| inlet = [circle(R - off, fn=N), circle(R - off, fn=N).up(Z_COLLAR)]
|
| for k in (0.3, 0.65):
|
| e = (1 - math.cos(math.pi * k)) / 2
|
| z = Z_COLLAR + (Z_TRANS - Z_COLLAR) * k
|
| z_in.append(z)
|
| inlet.append(rrect(R + (TRANS[0] - R) * e - off,
|
| R + (TRANS[1] - R) * e - off, 2 + 2 * e).up(z))
|
| inlet.append(rrect(TRANS[0] - off, TRANS[1] - off, 4).up(Z_TRANS))
|
|
|
| # branches: root -> middle -> outlet -> collar end, each a scaled
|
| # rounded rectangle rotated and moved into place
|
| def branch(c, angle, w, h):
|
| sizes = [(0.5, 6, 0), (0.46, 8, 30), (0.44, 8, 55), (0.44, 8, 80)]
|
| return [rrect(w * k - off, h * k - off, n)
|
| .rotate([0, angle, 0]).translate(at(c, angle, d))
|
| for k, n, d in sizes], [at(c, angle, d) for _, _, d in sizes]
|
| ra, ca = branch(A, -a_angle, a_w, a_h)
|
| rb, cb = branch(B, b_angle, b_w, b_h)
|
|
|
| parts = chain(inlet, [[0, 0, z] for z in z_in], 0) \
|
| + chain(ra, ca, -a_angle) + chain(rb, cb, b_angle)
|
| parts.append(top_view(inlet[-1], [ra[0], rb[0]])) # the crotch
|
| return parts, inlet[0], ra[-1], rb[-1]
|
|
|
|
|
| outer, o_in, o_a, o_b = skin(0)
|
| inner, i_in, i_a, i_b = skin(wall)
|
|
|
| parts = outer + inner + [
|
| rim(o_in, i_in, [0, 0, 0], 0),
|
| rim(o_a, i_a, at(A, -a_angle, 80), -a_angle),
|
| rim(o_b, i_b, at(B, b_angle, 80), b_angle),
|
| ]
|
|
|
| adapter = concat(*parts)
|
| adapter.show()
|