Repository navigation
Expand file tree
/
Copy pathrhombitrihexagon.scad
More file actions
383 lines (313 loc) · 8.3 KB
/
Copy pathrhombitrihexagon.scad
File metadata and controls
383 lines (313 loc) · 8.3 KB
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
// Rhombitrihexagonal Tiling
//
// https://en.wikipedia.org/wiki/Rhombitrihexagonal_tiling
//
/* [Rhombitrihexagon] */
// Column count
_CountX = 3;
// Row count
_CountY = 4;
// Hexagon radius
_HexRadius = 17.5;
// Inset of each element
_Inset = 0.5;
// Hexagon height
_HexHeight = 0.6;
// Square height
_SquareHeight = 0.6;
// Triangle height
_TriangleHeight = 0.6;
// Rim thickness
_RimThickness = 0.4;
// Rim height
_RimHeight = 0.4;
// Gap between rim elements
_RimGap = 1.5;
// Max rim elements on a shape
_RimMaxElements = 99;
/* [Extruders] */
// Hexagon extruder
_HexagonExtruder = 1;
// Square extruder
_SquareExtruder = 2;
// Triangle extruder
_TriangleExtruder = 3;
// Rim extruder
_RimExtruder = 4;
// [Extruder to render]
_WhichExtruder = "All"; // ["All", 1, 2, 3, 4, 5]
// Map a value of _WhichExtruder to an OpenSCAD color
function ExtruderColor(Extruder) =
(Extruder == 1 ) ? "red" :
(Extruder == 2 ) ? "green" :
(Extruder == 3 ) ? "blue" :
(Extruder == 4 ) ? "pink" :
(Extruder == 5 ) ? "yellow" :
"purple" ;
module __end_cust() {};
// If _WhichExtruder is "All" or is not "All" and matches the
// requested extruder, render the child nodes.
module Extruder(DoExtruder)
{
color(ExtruderColor(DoExtruder))
{
if (_WhichExtruder == "All" || DoExtruder == _WhichExtruder)
{
children();
}
}
}
//
// Render a rim for a polygon
//
module RimShape(Points, Inset, Thickness, Height, Gap, MaxElements, RimExtruder)
{
Extruder(RimExtruder)
{
for (r = [0 : MaxElements - 1])
{
linear_extrude(Height)
{
difference()
{
offset(delta=-(Inset + (r * Gap)))
{
polygon(Points);
}
offset(delta=-(Thickness + Inset + (r * Gap)))
{
polygon(Points);
}
}
}
}
}
}
//
// Render a square
//
module SquareShape(Points, Inset, Height, RimThickness, RimHeight, RimGap, RimMaxElements, SquareExtruder, RimExtruder)
{
union()
{
// Square
Extruder(SquareExtruder)
{
linear_extrude(Height)
{
offset(-Inset)
{
polygon(Points);
}
}
}
// Rim
translate([0, 0, Height])
{
RimShape(Points, Inset, RimThickness, RimHeight, RimGap, RimMaxElements, RimExtruder);
}
}
}
//
// Render a triangle
//
module TriangleShape(Points, Inset, Height, RimThickness, RimHeight, RimGap, RimMaxElements, TriangleExtruder, RimExtruder)
{
union()
{
// Triangle
Extruder(TriangleExtruder)
{
linear_extrude(Height)
{
offset(-Inset)
{
polygon(Points);
}
}
}
// Rim
translate([0, 0, Height])
{
RimShape(Points, Inset, RimThickness, RimHeight, RimGap, RimMaxElements, RimExtruder);
}
}
}
//
// Render a hexagon
//
module HexagonShape(Points, Inset, Height, RimThickness, RimHeight, RimGap, RimMaxElements, HexagonExtruder, RimExtruder)
{
union()
{
// Hexagon
Extruder(HexagonExtruder)
{
linear_extrude(Height)
{
offset(-Inset)
{
polygon(Points);
}
}
}
// Rim
translate([0, 0, Height])
{
RimShape(Points, Inset, RimThickness, RimHeight, RimGap, RimMaxElements, RimExtruder);
}
}
}
//
// Render a dodecagon
//
module DodecagonShape(Points, Inset, Height, RimThickness, RimHeight, RimGap, RimMaxElements)
{
linear_extrude(Height)
{
offset(-Inset)
{
polygon(Points);
}
}
}
//
// Render all or part of a rhombitrihexagon, with given inset, heights, and extruders
//
// Squares and triangles are numbered counter-clockwise, with 0 intersecting the Y axis on the +x side.
//
module Rhombitrihexagon(HexRadius, Inset, HexHeight, SquareHeight, TriangleHeight, SquareList, TriangleList, RimThickness, RimHeight, RimGap, RimMaxElements, HexagonExtruder, TriangleExtruder, SquareExtruder, RimExtruder)
{
// Compute apothem of hexagon then use it to compute radius of dodecagon
Apothem = 0.5 * sqrt(3) * HexRadius;
// Compute radius of dodecagon
DodRadius = sqrt((HexRadius / 2 * HexRadius / 2) + ((Apothem + HexRadius) * (Apothem + HexRadius)));
// Compute hexagon points
HexPoints = [for (t = [0 : 60 : 360]) [HexRadius * cos(t), HexRadius * sin(t)]];
// Compute dodecagon points
DodPoints = [for (t = [0 : 30 : 360]) [DodRadius * cos(t + 15), DodRadius * sin(t + 15)]];
// Form squares
Square0 =
[HexPoints[0],
DodPoints[0],
DodPoints[1],
HexPoints[1]
];
Square1 =
[HexPoints[1],
DodPoints[2],
DodPoints[3],
HexPoints[2]
];
Square2 =
[HexPoints[2],
DodPoints[4],
DodPoints[5],
HexPoints[3]
];
Square3 =
[HexPoints[3],
DodPoints[6],
DodPoints[7],
HexPoints[4]
];
Square4 =
[HexPoints[4],
DodPoints[8],
DodPoints[9],
HexPoints[5]
];
Square5 =
[HexPoints[5],
DodPoints[10],
DodPoints[11],
HexPoints[6]
];
Squares = [Square0, Square1, Square2, Square3, Square4, Square5];
// Form triangles
Triangle0 =
[HexPoints[0],
DodPoints[11],
DodPoints[0]];
Triangle1 =
[HexPoints[1],
DodPoints[1],
DodPoints[2]];
Triangle2 =
[HexPoints[2],
DodPoints[3],
DodPoints[4]];
Triangle3 =
[HexPoints[3],
DodPoints[5],
DodPoints[6]];
Triangle4 =
[HexPoints[4],
DodPoints[7],
DodPoints[8]];
Triangle5 =
[HexPoints[5],
DodPoints[9],
DodPoints[10]];
Triangles = [Triangle0, Triangle1, Triangle2, Triangle3, Triangle4, Triangle5];
// Render desired squares
for (Square = SquareList)
{
SquareShape(Squares[Square], Inset, SquareHeight, RimThickness, RimHeight, RimGap, RimMaxElements, SquareExtruder, RimExtruder);
}
// Render desired triangles
for (Triangle = TriangleList)
{
TriangleShape(Triangles[Triangle], Inset, TriangleHeight, RimThickness, RimHeight, RimGap, RimMaxElements, TriangleExtruder, RimExtruder);
}
// Render hexagon
HexagonShape(HexPoints, Inset, HexHeight, RimThickness, RimHeight, RimGap, RimMaxElements, HexagonExtruder, RimExtruder);
// Render dodecahedron (testing only)
//DodecagonShape(DodPoints, 0, HexHeight - 0.6, RimThickness, RimHeight, RimGap, RimMaxElements);
}
module main(HexRadius, CountX, CountY, Inset, HexHeight, SquareHeight, TriangleHeight, RimThickness, RimHeight, RimGap, RimMaxElements, HexagonExtruder, TriangleExtruder, SquareExtruder, RimExtruder)
{
AllSquares = [0, 1, 2, 3, 4, 5];
AllTriangles = [0, 1, 2, 3, 4, 5];
NextSquares = [0, 1, 2, 3, 5];
NextTriangles = [0, 1, 2, 3];
// Compute X Spacing
B = HexRadius * sin(60);
SpaceX = HexRadius + B + HexRadius + B + HexRadius;
// Compute Y Spacing
SpaceY = B + _HexRadius + B;
// Gap between rhombitrihexagons for debugging (set to 0 for production)
Explode = 0;
// Grid of nearly complete rhombitrihexagons at integer coordinates
for (X = [0 : CountX - 1])
{
for (Y = [0 : CountY - 1])
{
// Compute location
PointX = X * (SpaceX + Explode);
PointY = Y * (SpaceY + Explode);
// Figure out which squares and triangles to render
RenderSquares = (Y == 0) ? AllSquares : NextSquares;
RenderTriangles = (Y == 0) ? AllTriangles : NextTriangles;
translate([PointX, PointY, 0])
{
Rhombitrihexagon(HexRadius, Inset, HexHeight, SquareHeight, TriangleHeight, RenderSquares, RenderTriangles, RimThickness, RimHeight, RimGap, RimMaxElements, HexagonExtruder, TriangleExtruder, SquareExtruder, RimExtruder);
}
}
}
// Grid of very partial rhombitrihexagons at 0.5 coordinates
for (X = [0 : CountX - 2])
{
for (Y = [0 : CountY - 1])
{
// Compute location
PointX = (X * (SpaceX + Explode)) + SpaceX / 2 + Explode / 2;
PointY = (Y * (SpaceY + Explode)) + SpaceY / 2 + Explode / 2;
translate([PointX, PointY, 0])
{
Rhombitrihexagon(HexRadius, Inset, HexHeight, SquareHeight, TriangleHeight, [4], [], RimThickness, RimHeight, RimGap, RimMaxElements, HexagonExtruder, TriangleExtruder, SquareExtruder, RimExtruder);
}
}
}
}
main(_HexRadius, _CountX, _CountY, _Inset, _HexHeight, _SquareHeight, _TriangleHeight, _RimThickness, _RimHeight, _RimGap, _RimMaxElements, _HexagonExtruder, _TriangleExtruder, _SquareExtruder, _RimExtruder);