From 8113cfface61fe54f8927021b756f0d446612c4f Mon Sep 17 00:00:00 2001 From: Elmom Date: Mon, 30 Jan 2012 04:31:23 +0200 Subject: [PATCH] Added multiply.scad --- multiply.scad | 29 +++++++++++++++++++++++++++++ units.scad | 5 +++++ utilities.scad | 14 +++----------- 3 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 multiply.scad diff --git a/multiply.scad b/multiply.scad new file mode 100644 index 0000000..bca12c3 --- /dev/null +++ b/multiply.scad @@ -0,0 +1,29 @@ +/* + * Multiplication along certain curves + * + * Copyright by Elmo Mäntynen, 2012. + * Licenced under LGPL2 or later + */ + +include + +use + +// TODO check that the axis parameter works as intended +// Duplicate everything $no of times around an $axis, for $angle/360 rounds +module spin(no, angle=360, axis=Z){ + for (i = [1:no]){ + rotate(normalized_axis(axis)*angle*no/i) union(){ + for (i = [0 : $children-1]) child(i); + } + } +} + +//Doesn't work currently +module duplicate(axis=Z) spin(no=2, axis=axis) child(0); + +module linear_multiply(no, separation, axis=Z){ + for (i = [0:no-1]){ + translate(i*separation*axis) child(0); + } +} diff --git a/units.scad b/units.scad index 62662a9..61d0d7f 100644 --- a/units.scad +++ b/units.scad @@ -10,8 +10,13 @@ mm = 1; cm = 10 * mm; dm = 100 * mm; m = 1000 * mm; + inch = 25.4 * mm; +X = [1, 0, 0]; +Y = [0, 1, 0]; +Z = [0, 0, 1]; + M3 = 3*mm; M4 = 4*mm; M5 = 5*mm; diff --git a/utilities.scad b/utilities.scad index c35326a..01e4511 100644 --- a/utilities.scad +++ b/utilities.scad @@ -15,7 +15,9 @@ function length2(a) = sqrt( a[0]*a[0] + a[1]*a[1] ); function normalized(a) = a / (max(distance([0,0,0], a), 0.00001)); - +function normalized_axis(a) = a == "x" ? [1, 0, 0]: + a == "y" ? [0, 1, 0]: + a == "z" ? [0, 0, 1]: normalized(a); function angleOfNormalizedVector(n) = [0, -atan2(n[2], length2([n[0], n[1]])), atan2(n[1], n[0]) ]; @@ -23,16 +25,6 @@ function angle(v) = angleOfNormalizedVector(normalized(v)); function angleBetweenTwoPoints(a, b) = angle(normalized(b-a)); -// TODO check that the axis parameter works as intended -// Duplicate everything $no of times around an $axis, for $angle/360 rounds -module spin(no, angle=360, axis=[0, 0, 1]){ - for (i = [1:no]){ - rotate(normalized(axis)*angle*no/i) union(){ - for (i = [0 : $children-1]) child(i); - } - } -} - CENTER = 0; LEFT = -0.5;