From 03b2a96c266fa96a95d9d9b78605968102ed79b8 Mon Sep 17 00:00:00 2001 From: Quinn Date: Sat, 8 Jan 2022 15:43:37 -0800 Subject: [PATCH] Add shape gate definition, with sharpness --- poly_gates.scad | 71 ++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/poly_gates.scad b/poly_gates.scad index e9f1f84..f99f60b 100644 --- a/poly_gates.scad +++ b/poly_gates.scad @@ -3,60 +3,71 @@ gate_height = 50; sq_poly = let(corner = 1 / sqrt(2)) [ + [-corner, -corner], + [corner, -corner], [corner, corner], [-corner, corner], - [-corner, -corner], - [corner, -corner] ]; oct_poly = let(corner = 1 / sqrt(2))[ + [-corner, -corner], + [0,-1], + [corner, -corner], [1,0], [corner, corner], [0,1], [-corner, corner], [-1,0], - [-corner, -corner], - [0,-1], - [corner, -corner], ]; octn_poly = let(corner = 1 / sqrt(2 / 1.2))[ + [-corner, -corner], + [0,-1], + [corner, -corner], [1,0], [corner, corner], [0,1], [-corner, corner], [-1,0], - [-corner, -corner], - [0,-1], - [corner, -corner], ]; -function scale_xy_z(m, xy, z) = [ for (i = [0 : len(m) - 1]) [m[i].x * xy, m[i].y * xy, z]]; +function scale_xy(xy, m) = [ for (i = m) [i.x * xy, i.y * xy]]; -function throw_end(throw) = gate_height * tan(throw); +function add_z(z, m) = [ for (i = m) concat(i, z) ]; -function throw_points(shape, throw) = concat([[0,0,0]],scale_xy_z(shape, throw_end(throw), gate_height)); +function throw_end(throw, base_offset) = base_offset + gate_height * tan(throw); -function throw_faces(points) = [ - [each [1:len(points) - 1]], - for(i =[1:len(points) - 1]) let (next = i < len(points) - 1 ? i + 1 : 1) [i, next, 0] +function throw_polygons(shape, throw, base_offset = 0) = [ + add_z(0, scale_xy(base_offset, shape)), + add_z(gate_height, scale_xy(throw_end(throw, base_offset), shape)) ]; -module shape_gate (shape, throw, shaft_r, sharpness = 1) { - +function throw_points(shape, throw, base_offset = 0) = let(polys = throw_polygons(shape, throw, base_offset)) [ + for(i = [0,len(polys) - 1]) each polys[i] +]; + +function throw_faces(points) = let(length = len(points), half = len(points) / 2) [ + [for(i = [0:half - 1]) i], + [half, half + 1, 1, 0], + [for(i = [length - 1:-1:half]) i], + for(i = [1:half - 2]) [half + i, half + i + 1, i + 1, i], + [length - 1, half, 0, half - 1] +]; + +function lerp(a,b,t) = a + (b - a) * t; + +module shape_gate (shape, throw, shaft_r, sharpness = 0) { + sharpness = lerp(1, shaft_r, sharpness); + corner_r = shaft_r / sharpness; + corner_offset = corner_r * (sharpness - 1); + + points = throw_points(shape, throw, corner_offset); + echo(points); + echo(corner_r); + minkowski(){ + polyhedron(points, throw_faces(points)); + cylinder(1, corner_r); + } } -//echo(concat([[0,0,0]],scale_xy_z(sq_poly, 3, 3))); - -echo(throw_points(sq_poly, 15)); -echo(throw_faces(throw_points(sq_poly, 15))); - -points = throw_points(octn_poly, 15); -faces = throw_faces(points); - -minkowski() { -hull(){ - polyhedron(points, faces); -} -cylinder(1,3); -} +shape_gate(octn_poly, 10, 9.8 / 2, 0);