Use round poly in poly gates
This commit is contained in:
@@ -3,3 +3,5 @@ function normalize(vec) = vec / norm(vec);
|
|||||||
function lerp(a,b,t) = a + (b - a) * t;
|
function lerp(a,b,t) = a + (b - a) * t;
|
||||||
|
|
||||||
function scale_xy(shape, xy, allow_zero = false) = let(s = allow_zero ? xy : sign(xy == 0 ? 1 : xy) * max(abs(xy), 0.0001)) [ for (i = shape) [i.x * s, i.y * s]];
|
function scale_xy(shape, xy, allow_zero = false) = let(s = allow_zero ? xy : sign(xy == 0 ? 1 : xy) * max(abs(xy), 0.0001)) [ for (i = shape) [i.x * s, i.y * s]];
|
||||||
|
|
||||||
|
function add_z(z, m) = [ for (i = m) concat(i, z) ];
|
||||||
|
|||||||
+8
-66
@@ -1,75 +1,17 @@
|
|||||||
$fn = 32;
|
$fn = 32;
|
||||||
gate_height = 50;
|
gate_height = 50;
|
||||||
|
|
||||||
|
include<math.scad>;
|
||||||
|
include<shapes.scad>;
|
||||||
|
include<round_poly.scad>;
|
||||||
|
|
||||||
sq_poly = let(corner = 1 / sqrt(2)) [
|
function throw_travel(throw) = gate_height * tan(throw);
|
||||||
[-corner, -corner],
|
|
||||||
[corner, -corner],
|
|
||||||
[corner, corner],
|
|
||||||
[-corner, corner],
|
|
||||||
];
|
|
||||||
|
|
||||||
oct_poly = let(corner = 1 / sqrt(2))[
|
module shape_gate (shape, throw, shaft_r, sharpness = 0) {
|
||||||
[-corner, -corner],
|
hull(){
|
||||||
[0,-1],
|
round_poly(shape, shaft_r, sharpness);
|
||||||
[corner, -corner],
|
|
||||||
[1,0],
|
|
||||||
[corner, corner],
|
|
||||||
[0,1],
|
|
||||||
[-corner, corner],
|
|
||||||
[-1,0],
|
|
||||||
];
|
|
||||||
|
|
||||||
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],
|
|
||||||
];
|
|
||||||
|
|
||||||
function scale_xy(xy, m) = [ for (i = m) [i.x * xy, i.y * xy]];
|
|
||||||
|
|
||||||
function add_z(z, m) = [ for (i = m) concat(i, z) ];
|
|
||||||
|
|
||||||
function throw_end(throw, base_offset) = base_offset + gate_height * tan(throw);
|
|
||||||
|
|
||||||
function throw_polygons(shape, throw, base_offset = 0) = let(b_scale = base_offset < 0 ? 1 : base_offset)[
|
|
||||||
add_z(0, scale_xy(b_scale, shape)),
|
|
||||||
add_z(gate_height, scale_xy(throw_end(throw, base_offset), shape))
|
|
||||||
];
|
|
||||||
|
|
||||||
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 = 1) {
|
|
||||||
corner_r = shaft_r * sharpness;
|
|
||||||
corner_offset = shaft_r - corner_r;
|
|
||||||
|
|
||||||
points = throw_points(shape, throw, corner_offset);
|
|
||||||
|
|
||||||
minkowski(){
|
|
||||||
polyhedron(points, throw_faces(points));
|
|
||||||
cylinder(1, corner_r);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sharpness = $t;
|
shape_gate(sqr_poly, 10, 9 / 2, 1);
|
||||||
echo(sharpness);
|
|
||||||
|
|
||||||
shape_gate(sq_poly, 10, 9 / 2, 1);
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use<math.scad>;
|
include<math.scad>;
|
||||||
|
|
||||||
module round_poly(shape, radius, size = 0, sharpness = 0){
|
module round_poly(shape, radius, size = 0, sharpness = 0){
|
||||||
function grow(s, m) = [ for (i = s) i + normalize(i) * m];
|
function grow(s, m) = [ for (i = s) i + normalize(i) * m];
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
sqr_poly = let(corner = 1 / sqrt(2)) [
|
||||||
|
[-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],
|
||||||
|
];
|
||||||
|
|
||||||
|
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],
|
||||||
|
];
|
||||||
|
|
||||||
Reference in New Issue
Block a user