Added multiply.scad
This commit is contained in:
parent
3faafdd93e
commit
8113cfface
29
multiply.scad
Normal file
29
multiply.scad
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Multiplication along certain curves
|
||||
*
|
||||
* Copyright by Elmo Mäntynen, 2012.
|
||||
* Licenced under LGPL2 or later
|
||||
*/
|
||||
|
||||
include <units.scad>
|
||||
|
||||
use <utilities.scad>
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue