Skip to content

Commit 28f1636

Browse files
committed
Cubic_Array() , Radial_Array() functions
1 parent adef2d2 commit 28f1636

File tree

1 file changed

+139
-0
lines changed

1 file changed

+139
-0
lines changed

array.scad

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// array functions
2+
// by david powell
3+
// licence LGPL V2 or later
4+
//
5+
// this lib provides 2 functions
6+
// Cubic_Array() , and Radial_Array()
7+
//
8+
//Cubic_Array(sx,sy,sz,nx,ny,nz,center){childobject}
9+
// produces a cubic grid of child objects
10+
// sx,sy,sz = spacing for each axis
11+
// nx,ny,nz and number of objects on each axis
12+
// center = true/false on if geometery is centered or not
13+
//
14+
//
15+
//Radial_Array(a,n,r){child object}
16+
// produces a clockwise radial array of child objects rotated around the local z axis
17+
// a= interval angle
18+
// n= number of objects
19+
// r= radius distance
20+
//
21+
// remove // from following line to run test
22+
//Cubic_and_Radial_Array_Test();
23+
24+
module Cubic_and_Radial_Array_Test()
25+
{
26+
//center referance point
27+
translate([0,0,0])
28+
#cube([5,5,5],center=true);
29+
30+
//cubic array of 5*5*5 objects spaced 10*10*10 center relative
31+
Cubic_Array(10,10,10,5,5,5,center=true)
32+
{
33+
sphere(2.5,center=true,$fn=60);
34+
}
35+
36+
//a linear array allong x can be derived from the cubic array simply
37+
translate([60,0,0])
38+
Cubic_Array(10,0,0,5,1,1,center=false)
39+
{
40+
cube([5,5,5],center=true);
41+
}
42+
//a linear array allong y can be derived from the cubic array simply
43+
translate([0,60,0])
44+
Cubic_Array(0,10,0,1,5,1,center=false)
45+
{
46+
cube([5,5,5],center=true);
47+
}
48+
49+
//a linear array allong z can be derived from the cubic array simply
50+
translate([0,0,60])
51+
Cubic_Array(0,0,10,1,1,5,center=false)
52+
{
53+
cube([5,5,5],center=true);
54+
}
55+
56+
//a grid array allong x,y can be derived from the cubic array simply
57+
translate([0,0,-60])
58+
Cubic_Array(10,10,0,5,5,1,center=true)
59+
{
60+
cube([5,5,5],center=true);
61+
}
62+
63+
//radial array of 32 objects rotated though 10 degrees
64+
translate([0,0,0])
65+
Radial_Array(10,32,40)
66+
{
67+
cube([2,4,6],center=true);
68+
}
69+
70+
// a radial array of linear arrays
71+
72+
rotate([45,45,45])
73+
Radial_Array(10,36,40)
74+
{
75+
translate([0,10,0])
76+
Cubic_Array(0,10,0,1,5,1,center=false)
77+
{
78+
cube([2,3,4],center=true);
79+
}
80+
}
81+
82+
}
83+
84+
85+
// main lib modules
86+
module Cubic_Array(sx,sy,sz,nx,ny,nz,center)
87+
{
88+
if (center==true)
89+
{
90+
translate([-(((nx+1)*sx)/2),-(((ny+1)*sy)/2),-(((nz+1)*sz)/2)])
91+
{
92+
for(x=[1:nx])
93+
{
94+
for(y=[1:ny])
95+
{
96+
for(z=[1:nz])
97+
{
98+
translate([x*sx,y*sy,z*sz])
99+
child(center=true);
100+
}
101+
}
102+
}
103+
}
104+
}
105+
else
106+
{
107+
translate([0,0,0])
108+
{
109+
for(x=[1:nx])
110+
{
111+
for(y=[1:ny])
112+
{
113+
for(z=[1:nz])
114+
{
115+
translate([x*sx,y*sy,z*sz])
116+
child();
117+
}
118+
}
119+
}
120+
}
121+
}
122+
}
123+
124+
//
125+
//Radial_Array(a,n,r){child object}
126+
// produces a clockwise radial array of child objects rotated around the local z axis
127+
// a= interval angle
128+
// n= number of objects
129+
// r= radius distance
130+
//
131+
module Radial_Array(a,n,r)
132+
{
133+
for (k=[0:n-1])
134+
{
135+
rotate([0,0,-(a*k)])
136+
translate([0,r,0])
137+
child();
138+
}
139+
}

0 commit comments

Comments
 (0)