|
| 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 | + cylinder(h=10,r=.5,center=true); |
| 35 | + rotate([90,0,0]) |
| 36 | + cylinder(h=10,r=.5,center=true); |
| 37 | + rotate([0,90,0]) |
| 38 | + cylinder(h=10,r=.5,center=true); |
| 39 | + } |
| 40 | + |
| 41 | +//a linear array allong x can be derived from the cubic array simply |
| 42 | + translate([60,0,0]) |
| 43 | + Cubic_Array(10,0,0,5,1,1,center=false) |
| 44 | + { |
| 45 | + cube([5,5,5],center=true); |
| 46 | + } |
| 47 | +//a linear array allong y can be derived from the cubic array simply |
| 48 | + translate([0,60,0]) |
| 49 | + Cubic_Array(0,10,0,1,5,1,center=false) |
| 50 | + { |
| 51 | + cube([5,5,5],center=true); |
| 52 | + } |
| 53 | + |
| 54 | +//a linear array allong z can be derived from the cubic array simply |
| 55 | + translate([0,0,60]) |
| 56 | + Cubic_Array(0,0,10,1,1,5,center=false) |
| 57 | + { |
| 58 | + cube([5,5,5],center=true); |
| 59 | + } |
| 60 | + |
| 61 | +//a grid array allong x,y can be derived from the cubic array simply |
| 62 | + translate([0,0,-60]) |
| 63 | + Cubic_Array(10,10,0,5,5,1,center=true) |
| 64 | + { |
| 65 | + cube([5,5,5],center=true); |
| 66 | + } |
| 67 | + |
| 68 | +//radial array of 32 objects rotated though 10 degrees |
| 69 | + translate([0,0,0]) |
| 70 | + Radial_Array(10,32,40) |
| 71 | + { |
| 72 | + cube([2,4,6],center=true); |
| 73 | + } |
| 74 | + |
| 75 | +// a radial array of linear arrays |
| 76 | + |
| 77 | + rotate([45,45,45]) |
| 78 | + Radial_Array(10,36,40) |
| 79 | + { |
| 80 | + translate([0,10,0]) |
| 81 | + Cubic_Array(0,10,0,1,5,1,center=false) |
| 82 | + { |
| 83 | + cube([2,3,4],center=true); |
| 84 | + cylinder(h=10,r=.5,center=true); |
| 85 | + rotate([90,0,0]) |
| 86 | + cylinder(h=10,r=.5,center=true); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | +} |
| 91 | + |
| 92 | + |
| 93 | +// main lib modules |
| 94 | +module Cubic_Array(sx,sy,sz,nx,ny,nz,center) |
| 95 | + { |
| 96 | + if (center==true) |
| 97 | + { |
| 98 | + translate([-(((nx+1)*sx)/2),-(((ny+1)*sy)/2),-(((nz+1)*sz)/2)]) |
| 99 | + { |
| 100 | + for(x=[1:nx]) |
| 101 | + { |
| 102 | + for(y=[1:ny]) |
| 103 | + { |
| 104 | + for(z=[1:nz]) |
| 105 | + { |
| 106 | + translate([x*sx,y*sy,z*sz]) |
| 107 | + for (k = [0:$children-1]) child(k,center=true);; |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + else |
| 114 | + { |
| 115 | + translate([0,0,0]) |
| 116 | + { |
| 117 | + for(x=[1:nx]) |
| 118 | + { |
| 119 | + for(y=[1:ny]) |
| 120 | + { |
| 121 | + for(z=[1:nz]) |
| 122 | + { |
| 123 | + translate([x*sx,y*sy,z*sz]) |
| 124 | + for (k = [0:$children-1]) child(k); |
| 125 | + } |
| 126 | + } |
| 127 | + } |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | +// |
| 133 | +//Radial_Array(a,n,r){child object} |
| 134 | +// produces a clockwise radial array of child objects rotated around the local z axis |
| 135 | +// a= interval angle |
| 136 | +// n= number of objects |
| 137 | +// r= radius distance |
| 138 | +// |
| 139 | +module Radial_Array(a,n,r) |
| 140 | +{ |
| 141 | + for (k=[0:n-1]) |
| 142 | + { |
| 143 | + rotate([0,0,-(a*k)]) |
| 144 | + translate([0,r,0]) |
| 145 | + for (k = [0:$children-1]) child(k); |
| 146 | + } |
| 147 | +} |
0 commit comments