forked from SolidCode/MCAD
-
Notifications
You must be signed in to change notification settings - Fork 192
/
array.scad
114 lines (102 loc) · 2.7 KB
/
array.scad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// array functions
// by david powell
// licence LGPL V2 or later
//
// this lib provides 2 functions
// Cubic_Array() , and Radial_Array()
//
//Cubic_Array(sx,sy,sz,nx,ny,nz,center){childobject}
// produces a cubic grid of child objects
// sx,sy,sz = spacing for each axis
// nx,ny,nz and number of objects on each axis
// center = true/false on if geometery is centered or not
//
//
//Radial_Array(a,n,r){child object}
// produces a clockwise radial array of child objects rotated around the local z axis
// a= interval angle
// n= number of objects
// r= radius distance
//
// remove // from following line to run test
//Cubic_and_Radial_Array_Test();
module Cubic_and_Radial_Array_Test()
{
//center referance point
translate([0,0,0])
#cube([5,5,5],center=true);
//cubic array of 5*5*5 objects spaced 10*10*10 center relative
Cubic_Array(10,10,10,5,5,5,center=true)
{
sphere(2.5,$fn=60);
cylinder(h=10,r=.5,center=true);
rotate([90,0,0])
cylinder(h=10,r=.5,center=true);
rotate([0,90,0])
cylinder(h=10,r=.5,center=true);
}
//a linear array allong x can be derived from the cubic array simply
translate([60,0,0])
Cubic_Array(10,0,0,5,1,1,center=false)
{
cube([5,5,5],center=true);
}
//a linear array allong y can be derived from the cubic array simply
translate([0,60,0])
Cubic_Array(0,10,0,1,5,1,center=false)
{
cube([5,5,5],center=true);
}
//a linear array allong z can be derived from the cubic array simply
translate([0,0,60])
Cubic_Array(0,0,10,1,1,5,center=false)
{
cube([5,5,5],center=true);
}
//a grid array allong x,y can be derived from the cubic array simply
translate([0,0,-60])
Cubic_Array(10,10,0,5,5,1,center=true)
{
cube([5,5,5],center=true);
}
//radial array of 32 objects rotated though 10 degrees
translate([0,0,0])
Radial_Array(10,32,40)
{
cube([2,4,6],center=true);
}
// a radial array of linear arrays
rotate([45,45,45])
Radial_Array(10,36,40)
{
translate([0,10,0])
Cubic_Array(0,10,0,1,5,1,center=false)
{
cube([2,3,4],center=true);
cylinder(h=10,r=.5,center=true);
rotate([90,0,0])
cylinder(h=10,r=.5,center=true);
}
}
}
// main lib modules
module Cubic_Array(sx,sy,sz,nx,ny,nz,center) {
offset = center ? [-(((nx+1)*sx)/2),-(((ny+1)*sy)/2),-(((nz+1)*sz)/2)] : [0,0,0];
translate(offset)
for(x=[1:nx], y=[1:ny], z=[1:nz])
translate([x*sx,y*sy,z*sz])
children();
}
//
//Radial_Array(a,n,r){child object}
// produces a clockwise radial array of child objects rotated around the local z axis
// a= interval angle
// n= number of objects
// r= radius distance
//
module Radial_Array(a,n,r){
for (k=[0:n-1])
rotate([0,0,-(a*k)])
translate([0,r,0])
children();
}