openjscad-aurora-webapp
483 строки · 10.1 Кб
1include <maths_geodesic.scad>
2
3
4// Information about platonic solids
5// This information is useful in constructing the various solids
6// can be found here: http://en.wikipedia.org/wiki/Platonic_solid
7// V - vertices
8// E - edges
9// F - faces
10// number, V, E, F, schlafli symbol, dihedral angle, element, name
11//tetrahedron = [1, 4, 6, 4, [3,3], 70.5333, "fire", "tetrahedron"];
12//hexahedron = [2, 8, 12, 6, [4,3], 90, "earth", "cube"];
13//octahedron = [3, 6, 12, 8, [3,4], 109.467, "air", "air"];
14//dodecahedron = [4, 20, 30, 12, [5,3], 116.565, "ether", "universe"];
15//icosahedron = [5, 12, 30, 20, [3,5], 138.190, "water", "water"];
16
17// Schlafli representation for the platonic solids
18// Given this representation, we have enough information
19// to derive a number of other attributes of the solids
20tetra_sch = [3,3];
21hexa_sch = [4,3];
22octa_sch = [3,4];
23dodeca_sch = [5,3];
24icosa_sch = [3,5];
25
26// Given the schlafli representation, calculate
27// the number of edges, vertices, and faces for the solid
28function plat_edges(pq) = (2*pq[0]*pq[1])/
29((2*pq[0])-(pq[0]*pq[1])+(2*pq[1]));
30function plat_vertices(pq) = (2*plat_edges(pq))/pq[1];
31function plat_faces(pq) = (2*plat_edges(pq))/pq[0];
32
33
34// Calculate angular deficiency of each vertex in a platonic solid
35// p - sides
36// q - number of edges per vertex
37//function angular_defect(pq) = 360 - (poly_single_interior_angle(pq)*pq[1]);
38function plat_deficiency(pq) = DEGREES(2*Cpi - pq[1]*Cpi*(1-2/pq[0]));
39
40function plat_dihedral(pq) = 2 * asin( cos(180/pq[1])/sin(180/pq[0]));
41
42function plat_circumradius(pq, a) =
43(a/2)*
44tan(Cpi/pq[1])*
45tan(plat_dihedral(pq)/2);
46
47function plat_midradius(pq, a) =
48(a/2)*
49cot(Cpi/pq[0])*
50tan(plat_dihedral(pq)/2);
51
52function plat_inradius(pq,a) =
53a/(2*tan(DEGREES(Cpi/pq[0])))*
54sqrt((1-cos(plat_dihedral(pq)))/(1+cos(plat_dihedral(pq))));
55
56//================================================
57// Tetrahedron
58//================================================
59tetra_cart = [
60[+1, +1, +1],
61[-1, -1, +1],
62[-1, +1, -1],
63[+1, -1, -1]
64];
65
66function tetra_unit(rad=1) = [
67sph_to_cart(sphu_from_cart(tetra_cart[0], rad)),
68sph_to_cart(sphu_from_cart(tetra_cart[1], rad)),
69sph_to_cart(sphu_from_cart(tetra_cart[2], rad)),
70sph_to_cart(sphu_from_cart(tetra_cart[3], rad)),
71];
72
73
74tetrafaces = [
75[0, 3, 1],
76[0,1,2],
77[2,1,3],
78[0,2,3]
79];
80
81tetra_edges = [
82[0,1],
83[0,2],
84[0,3],
85[1,2],
86[1,3],
87[2,3],
88];
89
90function tetrahedron(rad=1) = [tetra_unit(rad), tetrafaces, tetra_edges];
91
92
93//================================================
94// Hexahedron - Cube
95//================================================
96// vertices for a unit cube with sides of length 1
97hexa_cart = [
98[0.5, 0.5, 0.5],
99[-0.5, 0.5, 0.5],
100[-0.5, -0.5, 0.5],
101[0.5, -0.5, 0.5],
102[0.5, 0.5, -0.5],
103[-0.5, 0.5, -0.5],
104[-0.5, -0.5, -0.5],
105[0.5, -0.5, -0.5],
106];
107
108function hexa_unit(rad=1) = [
109sph_to_cart(sphu_from_cart(hexa_cart[0], rad)),
110sph_to_cart(sphu_from_cart(hexa_cart[1], rad)),
111sph_to_cart(sphu_from_cart(hexa_cart[2], rad)),
112sph_to_cart(sphu_from_cart(hexa_cart[3], rad)),
113sph_to_cart(sphu_from_cart(hexa_cart[4], rad)),
114sph_to_cart(sphu_from_cart(hexa_cart[5], rad)),
115sph_to_cart(sphu_from_cart(hexa_cart[6], rad)),
116sph_to_cart(sphu_from_cart(hexa_cart[7], rad)),
117];
118
119
120// enumerate the faces of a cube
121// vertex order is clockwise winding
122hexafaces = [
123[0,3,2,1], // top
124[0,1,5,4],
125[1,2,6,5],
126[2,3,7,6],
127[3,0,4,7],
128[4,5,6,7], // bottom
129];
130
131hexa_edges = [
132[0,1],
133[0,3],
134[0,4],
135[1,2],
136[1,5],
137[2,3],
138[2,6],
139[3,7],
140[4,5],
141[4,7],
142[5,4],
143[5,6],
144[6,7],
145];
146
147
148function hexahedron(rad=1) =[hexa_unit(rad), hexafaces, hexa_edges];
149
150
151//================================================
152// Octahedron
153//================================================
154
155octa_cart = [
156[+1, 0, 0], // + x axis
157[-1, 0, 0], // - x axis
158[0, +1, 0], // + y axis
159[0, -1, 0], // - y axis
160[0, 0, +1], // + z axis
161[0, 0, -1] // - z axis
162];
163
164function octa_unit(rad=1) = [
165sph_to_cart(sphu_from_cart(octa_cart[0], rad)),
166sph_to_cart(sphu_from_cart(octa_cart[1], rad)),
167sph_to_cart(sphu_from_cart(octa_cart[2], rad)),
168sph_to_cart(sphu_from_cart(octa_cart[3], rad)),
169sph_to_cart(sphu_from_cart(octa_cart[4], rad)),
170sph_to_cart(sphu_from_cart(octa_cart[5], rad)),
171];
172
173octafaces = [
174[4,2,0],
175[4,0,3],
176[4,3,1],
177[4,1,2],
178[5,0,2],
179[5,3,0],
180[5,1,3],
181[5,2,1]
182];
183
184octa_edges = [
185[0,2],
186[0,3],
187[0,4],
188[0,5],
189[1,2],
190[1,3],
191[1,4],
192[1,5],
193[2,4],
194[2,5],
195[3,4],
196[3,5],
197];
198
199function octahedron(rad=1) = [octa_unit(rad), octafaces, octa_edges];
200
201//================================================
202// Dodecahedron
203//================================================
204// (+-1, +-1, +-1)
205// (0, +-1/Cphi, +-Cphi)
206// (+-1/Cphi, +-Cphi, 0)
207// (+-Cphi, 0, +-1/Cphi)
208
209dodeca_cart = [
210[+1, +1, +1], // 0, 0
211[+1, -1, +1], // 0, 1
212[-1, -1, +1], // 0, 2
213[-1, +1, +1], // 0, 3
214
215[+1, +1, -1], // 1, 4
216[-1, +1, -1], // 1, 5
217[-1, -1, -1], // 1, 6
218[+1, -1, -1], // 1, 7
219
220[0, +1/Cphi, +Cphi], // 2, 8
221[0, -1/Cphi, +Cphi], // 2, 9
222[0, -1/Cphi, -Cphi], // 2, 10
223[0, +1/Cphi, -Cphi], // 2, 11
224
225[-1/Cphi, +Cphi, 0], // 3, 12
226[+1/Cphi, +Cphi, 0], // 3, 13
227[+1/Cphi, -Cphi, 0], // 3, 14
228[-1/Cphi, -Cphi, 0], // 3, 15
229
230[-Cphi, 0, +1/Cphi], // 4, 16
231[+Cphi, 0, +1/Cphi], // 4, 17
232[+Cphi, 0, -1/Cphi], // 4, 18
233[-Cphi, 0, -1/Cphi], // 4, 19
234];
235
236function dodeca_unit(rad=1) = [
237sph_to_cart(sphu_from_cart(dodeca_cart[0], rad)),
238sph_to_cart(sphu_from_cart(dodeca_cart[1], rad)),
239sph_to_cart(sphu_from_cart(dodeca_cart[2], rad)),
240sph_to_cart(sphu_from_cart(dodeca_cart[3], rad)),
241sph_to_cart(sphu_from_cart(dodeca_cart[4], rad)),
242sph_to_cart(sphu_from_cart(dodeca_cart[5], rad)),
243sph_to_cart(sphu_from_cart(dodeca_cart[6], rad)),
244sph_to_cart(sphu_from_cart(dodeca_cart[7], rad)),
245sph_to_cart(sphu_from_cart(dodeca_cart[8], rad)),
246sph_to_cart(sphu_from_cart(dodeca_cart[9], rad)),
247sph_to_cart(sphu_from_cart(dodeca_cart[10], rad)),
248sph_to_cart(sphu_from_cart(dodeca_cart[11], rad)),
249sph_to_cart(sphu_from_cart(dodeca_cart[12], rad)),
250sph_to_cart(sphu_from_cart(dodeca_cart[13], rad)),
251sph_to_cart(sphu_from_cart(dodeca_cart[14], rad)),
252sph_to_cart(sphu_from_cart(dodeca_cart[15], rad)),
253sph_to_cart(sphu_from_cart(dodeca_cart[16], rad)),
254sph_to_cart(sphu_from_cart(dodeca_cart[17], rad)),
255sph_to_cart(sphu_from_cart(dodeca_cart[18], rad)),
256sph_to_cart(sphu_from_cart(dodeca_cart[19], rad)),
257];
258
259
260
261// These are the pentagon faces
262// but CGAL has a problem rendering if things are
263// not EXACTLY coplanar
264// so use the triangle faces instead
265//dodeca_faces=[
266// [1,9,8,0,17],
267// [9,1,14,15,2],
268// [9,2,16,3,8],
269// [8,3,12,13,0],
270// [0,13,4,18,17],
271// [1,17,18,7,14],
272// [15,14,7,10,6],
273// [2,15,6,19,16],
274// [16,19,5,12,3],
275// [12,5,11,4,13],
276// [18,4,11,10,7],
277// [19,6,10,11,5]
278// ];
279dodeca_faces = [
280[1,9,8],
281[1,8,0],
282[1,0,17],
283
284[9,1,14],
285[9,14,15],
286[9,15,2],
287
288[9,2,16],
289[9,16,3],
290[9,3,8],
291
292[8,3,12],
293[8,12,13],
294[8,13,0],
295
296[0,13,4],
297[0,4,18],
298[0,18,17],
299
300[1,17,18],
301[1,18,7],
302[1,7,14],
303
304[15,14,7],
305[15,7,10],
306[15,10,6],
307
308[2,15,6],
309[2,6,19],
310[2,19,16],
311
312[16,19,5],
313[16,5,12],
314[16,12,3],
315
316[12,5,11],
317[12,11,4],
318[12,4,13],
319
320[18,4,11],
321[18,11,10],
322[18,10,7],
323
324[19,6,10],
325[19,10,11],
326[19,11,5]
327];
328
329dodeca_edges=[
330[0,8],
331[0,13],
332[0,17],
333
334[1,9],
335[1,14],
336[1,17],
337
338[2,9],
339[2,15],
340[2,16],
341
342[3,8],
343[3,12],
344[3,16],
345
346[4,11],
347[4,13],
348[4,18],
349
350[5,11],
351[5,12],
352[5,19],
353
354[6,10],
355[6,15],
356[6,19],
357
358[7,10],
359[7,14],
360[7,18],
361
362[8,9],
363[10,11],
364[12,13],
365[14,15],
366[16,19],
367[17,18],
368];
369
370function dodecahedron(rad=1) = [dodeca_unit(rad), dodeca_faces, dodeca_edges];
371
372//================================================
373// Icosahedron
374//================================================
375//
376// (0, +-1, +-Cphi)
377// (+-Cphi, 0, +-1)
378// (+-1, +-Cphi, 0)
379
380icosa_cart = [
381[0, +1, +Cphi], // 0
382[0, +1, -Cphi], // 1
383[0, -1, -Cphi], // 2
384[0, -1, +Cphi], // 3
385
386[+Cphi, 0, +1], // 4
387[+Cphi, 0, -1], // 5
388[-Cphi, 0, -1], // 6
389[-Cphi, 0, +1], // 7
390
391[+1, +Cphi, 0], // 8
392[+1, -Cphi, 0], // 9
393[-1, -Cphi, 0], // 10
394[-1, +Cphi, 0] // 11
395];
396
397function icosa_sph(rad=1) = [
398sphu_from_cart(icosa_cart[0], rad),
399sphu_from_cart(icosa_cart[1], rad),
400sphu_from_cart(icosa_cart[2], rad),
401sphu_from_cart(icosa_cart[3], rad),
402sphu_from_cart(icosa_cart[4], rad),
403sphu_from_cart(icosa_cart[5], rad),
404sphu_from_cart(icosa_cart[6], rad),
405sphu_from_cart(icosa_cart[7], rad),
406sphu_from_cart(icosa_cart[8], rad),
407sphu_from_cart(icosa_cart[9], rad),
408sphu_from_cart(icosa_cart[10], rad),
409sphu_from_cart(icosa_cart[11], rad),
410];
411
412function icosa_unit(rad=1) = [
413sph_to_cart(sphu_from_cart(icosa_cart[0], rad)),
414sph_to_cart(sphu_from_cart(icosa_cart[1], rad)),
415sph_to_cart(sphu_from_cart(icosa_cart[2], rad)),
416sph_to_cart(sphu_from_cart(icosa_cart[3], rad)),
417sph_to_cart(sphu_from_cart(icosa_cart[4], rad)),
418sph_to_cart(sphu_from_cart(icosa_cart[5], rad)),
419sph_to_cart(sphu_from_cart(icosa_cart[6], rad)),
420sph_to_cart(sphu_from_cart(icosa_cart[7], rad)),
421sph_to_cart(sphu_from_cart(icosa_cart[8], rad)),
422sph_to_cart(sphu_from_cart(icosa_cart[9], rad)),
423sph_to_cart(sphu_from_cart(icosa_cart[10], rad)),
424sph_to_cart(sphu_from_cart(icosa_cart[11], rad)),
425];
426
427icosa_faces = [
428[3,0,4],
429[3,4,9],
430[3,9,10],
431[3,10,7],
432[3,7,0],
433[0,8,4],
434[0,7,11],
435[0,11,8],
436[4,8,5],
437[4,5,9],
438[7,10,6],
439[7,6,11],
440[9,5,2],
441[9,2,10],
442[2,6,10],
443[1,5,8],
444[1,8,11],
445[1,11,6],
446[5,1,2],
447[2,1,6]
448];
449
450icosa_edges = [
451[0,3],
452[0,4],
453[0,7],
454[0,8],
455[0,11],
456[1,5],
457[1,8],
458[1,11],
459[1,6],
460[1,2],
461[2,5],
462[2,6],
463[2,9],
464[2,10],
465[3,4],
466[3,9],
467[3,10],
468[3,7],
469[4,5],
470[4,8],
471[4,9],
472[5,8],
473[5,9],
474[6,7],
475[6,10],
476[6,11],
477[7,10],
478[7,11],
479[8,11],
480[9,10],
481];
482
483function icosahedron(rad=1) = [icosa_unit(rad), icosa_faces, icosa_edges];
484