-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparemetric_tray_generator.scad
354 lines (297 loc) · 14.1 KB
/
paremetric_tray_generator.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
// Copyright 2023 Stefano Linguerri
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.¢
// See the License for the specific language governing permissions and
// limitations under the License.
//Number of columns for this tray
cols = 6;
//Number of rows for this tray
rows = 7;
//heigh (thickness) of this tray
height = 5;
//new base width
new_base_width = 25;
//new base length
new_base_length = 25;
// existing base width of adapted models
adapted_base_width = 21.1;
// existing base length of adapted models
adapted_base_length = 21.1;
//minimum bottom height (thickness) of the insets for the bases
height_offset = 2;
//Inset of the top of the tray: greater the value greater the slope of the tray
inset = 1;
//if base adapted are round (in this case adapted_base_width is considered as the diameter of the round base)
isRound_adapted = false;
//magnets height (if greater than zero will generate the insets)
magnets_height = 0;
//magnets radius
magnets_radius = 0;
//if the tray is for lance formation, use only the number of rows to genrate the tray
isLanceFormation = false;
//Create a standard (non an adpater) movement tray for given new_base_length x new_base_width
createEmptyMovementTray = false;
//Put a mark to show the new base widh/length on the adapter
markBases = false;
module tray(cols, rows, height, new_base_width, new_base_length, adapted_base_width, adapted_base_length, inset, margin_for_empty_tray) {
b_total_cols = (new_base_width * cols) + margin_for_empty_tray;
b_total_rows = (new_base_length * rows)+ margin_for_empty_tray;
t_total_cols = (new_base_width * cols - inset *2) + margin_for_empty_tray;
t_total_rows = (new_base_length * rows - inset *2) + margin_for_empty_tray;
polyhedron(
points=[
[0,0,0], //base bottom left
[b_total_cols,0,0], //base bottom right
[b_total_cols,b_total_rows,0], //base top right
[0,b_total_rows,0], //base top left
[inset, inset, height], //surface bottom left
[inset + t_total_cols, inset, height], //surface bottom right
[inset + t_total_cols, inset + t_total_rows, height], //surface top right
[inset, inset + t_total_rows, height] //surface top left
],
faces =[
[0,1,2,3],
[4,5,1,0],
[5,6,2,1],
[6,7,3,2],
[7,4,0,3],
[7,6,5,4]
]
);
}
//this module will create the hole in the "empty" classic movement tray
module empty_tray_hole(cols, rows, height_offset, new_base_width, new_base_length, adapted_base_width, adapted_base_length, inset, margin_for_empty_tray) {
t_total_cols = (new_base_width * cols ) ;
t_total_rows = (new_base_length * rows);
translate(
[margin_for_empty_tray/2, //row
margin_for_empty_tray/2, //col
height_offset]
)
cube([t_total_cols,t_total_rows+margin_for_empty_tray, 30]);
}
module adapted_base_holes(cols, rows, height_offset, new_base_width, new_base_length, adapted_base_width, adapted_base_length) {
gap_w = new_base_width - adapted_base_width;
gap_l = new_base_length - adapted_base_length;
for (c = [0:cols-1]){
for (r = [0:rows-1]){
translate(
[gap_w/2 + (c*adapted_base_width) + (c*gap_w), //row
gap_l/2 + (r*adapted_base_length) + (r*gap_l), //col
height_offset]
)
cube([adapted_base_width,adapted_base_length, 30]);
}
}
}
module adapted_base_holes_round(cols, rows, height_offset, new_base_width, new_base_length, adapted_base_width, adapted_base_length) {
for (c = [0:cols-1]){
for (r = [0:rows-1]){
translate(
[new_base_width/2 + new_base_width * c , //row
new_base_length/2 + new_base_length * r, //col
height_offset]
)
//resize([adapted_base_width,adapted_base_length])
cylinder(r = adapted_base_width/2, h = height);
}
}
}
module magnets_holes (cols, rows, new_base_width, new_base_length, magnets_height, magnets_radius, height, height_offset) {
for (c = [0:cols-1]){
for (r = [0:rows-1]){
translate(
[new_base_width/2 + new_base_width * c , //row
new_base_length/2 + new_base_length * r, //col
height_offset-magnets_height+0.01]
)
cylinder(r = magnets_radius/2, h = magnets_height+0.01,$fn=20);
}
}
}
/// BASE MARKER
module mark_new_bases (cols, rows, new_base_width, new_base_length, magnets_height, magnets_radius, height, height_offset) {
color ([0.9, 0.4, 0.4])
{
for (c = [1:cols-1]){
translate(
[new_base_width * c-inset/2 , //col
new_base_length * 0, //row
height+height/5]
)
rotate([-90,0,0]) {
linear_extrude(new_base_length*rows) {
polygon(points=[[0,0],[1,0],[inset/2,(height-height_offset)]], paths=[[0,1,2]]);
}
}
}
for (r = [1:rows-1]){
translate(
[new_base_width * 0 , //col
new_base_length * r-inset/2, //row
height+height/5]
)
rotate([90,90,90]) {
linear_extrude(new_base_width*cols) {
polygon(points=[[0,1],[(height-height_offset),inset/2],[0,0]], paths=[[0,1,2]]);
}
}
}
}
}
module lance_formation (cols, rows, new_base_width, new_base_length, magnets_height, magnets_radius, height, height_offset, inset, margin_for_empty_tray) {
for (thisRow = [0:rows-1]){
translate( [0,thisRow*new_base_length,0]){
for (thisCol = [0:thisRow]){
translate( [(new_base_width/2)*thisRow-(new_base_width*thisCol),0,0]){
//color([0.4, rands(0.01, 1,1)[0],rands(0.01, 1,1)[0] ])
color ([0.5, 0.5, 0.5])
{
lance_sloped_slot(thisCol+1, thisRow+1 == rows, height, new_base_width, new_base_length, adapted_base_width, adapted_base_length, inset, margin_for_empty_tray);
}
}
}
}
}
}
////////////////////////////////
// LANCE FORMATION //
////////////////////////////////
module lance_sloped_slot(cols, isLastRow, height, new_base_width, new_base_length, adapted_base_width, adapted_base_length, inset, margin_for_empty_tray) {
rows = 1;
b_total_cols = (new_base_width * cols) + margin_for_empty_tray;
b_total_rows = (new_base_length * rows)+ margin_for_empty_tray;
t_total_cols = (new_base_width * cols - inset *2) + margin_for_empty_tray;
t_total_rows = (new_base_length * rows - inset *2) + margin_for_empty_tray;
polyhedron(
points=[
[0,0,0], //base bottom left
[b_total_cols,0,0], //base bottom right
[b_total_cols,b_total_rows,0], //base top right
[0,b_total_rows,0], //base top left
[inset, inset, height], //surface bottom left
[inset + t_total_cols, inset, height], //surface bottom right
[inset + t_total_cols,
isLastRow ? inset + t_total_rows : inset*3 + t_total_rows, //if last row we set the slope otherwise we move the y of the point to reach the next row
height], //surface top right
[inset,
isLastRow ? inset + t_total_rows : inset*3 + t_total_rows,//if last row we set the slope otherwise we move the y of the point to reach the next row
height]//surface top left
],
faces =[
[0,1,2,3],
[4,5,1,0],
[5,6,2,1],
[6,7,3,2],
[7,4,0,3],
[7,6,5,4]
]
);
}
module lance_formation_hole (cols, rows, new_base_width, new_base_length, magnets_height, magnets_radius, height, height_offset) {
gap_w = new_base_width - adapted_base_width;
gap_l = new_base_length - adapted_base_length;
for (thisRow = [0:rows-1]){
translate( [0,thisRow*new_base_length+gap_l/2,height_offset]){
for (thisCol = [0:thisRow]){
translate( [(new_base_width/2)*thisRow-(new_base_width*thisCol)+gap_w/2,0,0]){
color([0.7, 0.7,0.7 ]){
cube([adapted_base_width, adapted_base_length,height+2 ]);
}
}
}
}
}
}
//Standard movement tray
module lance_formation_tray_hole (cols, rows, new_base_width, new_base_length, magnets_height, magnets_radius, height, height_offset, inset, margin_for_empty_tray) {
gap_w = new_base_width - adapted_base_width;
gap_l = new_base_length - adapted_base_length;
for (thisRow = [0:rows-1]){
translate( [0,thisRow*new_base_length+margin_for_empty_tray/2,height_offset]){
for (thisCol = [0:thisRow]){
translate( [(new_base_width/2)*thisRow-(new_base_width*thisCol)+margin_for_empty_tray/2,0,0]){
color([0.7, 0.7,0.7 ]){
cube([new_base_width, new_base_length*2+margin_for_empty_tray,height+2 ]);
}
}
}
}
}
}
module lance_formation_magnets_hole (cols, rows, new_base_width, new_base_length, magnets_height, magnets_radius, height, height_offset) {
gap_w = new_base_width - adapted_base_width;
gap_l = new_base_length - adapted_base_length;
for (thisRow = [0:rows-1]){
translate( [0,(thisRow+1)*new_base_length-new_base_length/2,height_offset-magnets_height+0.01]){
for (thisCol = [0:thisRow]){
translate( [(new_base_width/2)*thisRow-(new_base_width*thisCol)+gap_w/2+new_base_width/2,0,0]){
color([0.7, 0.7,0.7 ]){
cylinder(r = magnets_radius/2, h = magnets_height+0.01,$fn=20);
}
}
}
}
}
}
//Ranked movement tray
if(!isLanceFormation){
difference(){
color ([0.5, 0.5, 0.5]) {
if(!createEmptyMovementTray){
tray(cols, rows, height, new_base_width, new_base_length, adapted_base_width, adapted_base_length, inset, 0);
}else{
tray(cols, rows, height, new_base_width, new_base_length, adapted_base_width, adapted_base_length, inset, 3);
}
}
color ([0.7, 0.7, 0.7]) {
if (magnets_height > 0){
echo ("magnets");
magnets_holes (cols, rows, new_base_width, new_base_length, magnets_height, magnets_radius,height, height_offset);
}
if(!createEmptyMovementTray){
if(!isRound_adapted){
adapted_base_holes(cols, rows, height_offset, new_base_width, new_base_length, adapted_base_width, adapted_base_length);
}else{
adapted_base_holes_round(cols, rows, height_offset, new_base_width, new_base_length, adapted_base_width, adapted_base_length);
}
}else{
empty_tray_hole(cols, rows, height_offset, new_base_width, new_base_length, adapted_base_width, adapted_base_length, inset, 3);
}
}
if(markBases){
echo("mark it");
mark_new_bases (cols, rows, new_base_width, new_base_length, magnets_height, magnets_radius, height, height_offset);
}
}
}
//Lance formation movment tray
if(isLanceFormation){
difference(){
if(!createEmptyMovementTray){
union() {
lance_formation (cols, rows, new_base_width, new_base_length, magnets_height, magnets_radius, height, height_offset, inset, 0);
}
}else{
union() {
lance_formation (cols, rows, new_base_width, new_base_length, magnets_height, magnets_radius, height, height_offset, inset, 3);
}
}
if(!createEmptyMovementTray){
lance_formation_hole (cols, rows, new_base_width, new_base_length, magnets_height, magnets_radius, height, height_offset);
}else{
lance_formation_tray_hole(cols, rows, new_base_width, new_base_length, magnets_height, magnets_radius, height, height_offset, inset, 3);
}
if (magnets_height > 0){
echo ("magnets lance");
lance_formation_magnets_hole (cols, rows, new_base_width, new_base_length, magnets_height, magnets_radius,height, height_offset);
}
}
}