Add math library

This commit is contained in:
Quinn
2022-01-09 15:10:14 -08:00
parent b0cd663d6d
commit bfd9286a51
2 changed files with 10 additions and 28 deletions
+5
View File
@@ -0,0 +1,5 @@
function normalize(vec) = vec / norm(vec);
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]];
+4 -27
View File
@@ -1,30 +1,9 @@
$fn=32; use<math.scad>;
card = 1;
corn = 1 / sqrt(2);
oct = [
[card,0],
[corn,corn],
[0,card],
[-corn,corn],
[-card,0],
[-corn,-corn],
[0,-card],
[corn,-corn]
];
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 normalize(vec) = vec / norm(vec);
function grow(shape, mag) = [ for (i = shape) i + normalize(i) * mag];
function add_radius(shape, rad) = grow(shape, rad/cos(180/len(shape)));
function lerp(a,b,t) = a + (b - a) * t;
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 add_radius(s, r) = grow(s, r/cos(180/len(s)));
corner_r = lerp(radius, 0, sharpness); corner_r = lerp(radius, 0, sharpness);
corner_offset = lerp(0, radius, sharpness); corner_offset = lerp(0, radius, sharpness);
@@ -33,5 +12,3 @@ module round_poly(shape, radius, size = 0, sharpness = 0){
circle(max(corner_r, 0.0001)); circle(max(corner_r, 0.0001));
} }
} }
round_poly(oct, radius, 4, 0);