openjscad-aurora-webapp
615 строк · 12.1 Кб
1include <platonic.scad>
2
3//test_duals();
4test_wireframes();
5//test_polyhedron();
6
7//=======================================
8// WIREFRAMES
9//=======================================
10module test_wireframes()
11{
12//rotate(v=[-1,1,0], a=54.7356)
13//display_polywireframe(tetrahedron(40), radius=2.5, style=0);
14
15//display_polywireframe(hexahedron(20), radius=2.5, style=0, smoothness=24);
16
17//rotate(v=[-1,1,0], a=54.7356)
18//display_polywireframe(octahedron(20), radius=2.5, style=0, smoothness=24);
19
20//rotate(v=[1,0,0], a=plat_dihedral(dodeca_sch)/2) // dihedral
21//display_polywireframe(dodecahedron(20), radius=2.5, style=0, smoothness=24);
22
23rotate(v=[-1,1,0], a=54.7356)
24display_polywireframe(icosahedron(30), radius=2.5, style=0);
25}
26
27
28//====================================
29// Utility functions
30//====================================
31function VMAG(v) = sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
32
33function LineRotations(v) = [
34atan2(sqrt(v[0]*v[0]+v[1]*v[1]), v[2]),
350,
36atan2(v[1], v[0])+90];
37
38function parseSeg(seg) = [
39seg[0],
40LineRotations(seg[1]-seg[0]),
41VMAG(seg[1]-seg[0])
42];
43
44
45module PlaceLine(seg, radius=0.025, style=1, smoothness=24)
46{
47$fn=smoothness;
48diameter = radius*2;
49side = sqrt((diameter*diameter)/2);
50
51
52params = parseSeg(seg);
53
54origin = params[0];
55rot = params[1];
56len = params[2];
57
58translate(origin)
59rotate(rot)
60{
61if (style == 0) // cylinders, with no end caps
62{
63cylinder(r=radius, h=len);
64} else if (style == 1) // cylinders with rounded end caps
65{
66cylinder(r=radius, h=len);
67
68// Cap with spheres
69sphere(r=radius);
70
71translate([0,0,len])
72sphere(r=radius);
73} else // Second style is experimental
74{
75// translate([-side/2, -side/2,0])
76// cube(size=[side, side, len]);
77//
78// translate([-side/2, -side/2, -side/2])
79// cube(size=[side, side, side]);
80//
81// translate([-side/2, -side/2, (-side/2)+len])
82// cube(size=[side, side, side]);
83}
84}
85}
86
87module display_polywireframe(poly, radius=0.025, style=1, smoothness=24)
88{
89
90// For each edge
91// Draw the wireframe
92for (edge = poly[2])
93{
94PlaceLine([poly[0][edge[0]], poly[0][edge[1]]],
95radius=radius,
96style = style,
97smoothness=smoothness);
98}
99
100display_poly_verts(poly[0], radius, $fn=smoothness);
101}
102
103module display_polyhedron(poly)
104{
105polyhedron(points = poly[0], triangles = poly[1]);
106}
107
108module display_platonics(rad=1)
109{
110// At the center, the self dual tetrahedron
111display_polyhedron(tetrahedron(rad));
112
113
114translate(rad*[3, 3, 0])
115display_polyhedron(icosahedron(rad));
116
117translate(rad*[-3, -3, 0])
118display_polyhedron(dodecahedron(rad));
119
120
121translate(rad*[-3, 3, 0])
122display_polyhedron(hexahedron(rad));
123translate(rad*[3,-3,0])
124display_polyhedron(octahedron(rad));
125
126
127}
128
129module print_spherical_to_cartesian(sverts)
130{
131for (vert = sverts)
132{
133echo(sph_to_cart(vert));
134}
135}
136
137module print_cartesian_to_spherical(cverts)
138{
139for (vert = cverts)
140{
141echo(sph_from_cart(vert));
142}
143}
144
145module display_verts(verts, indices, numverts, radius=0.1)
146{
147//echo(verts);
148
149for (i = [0:numverts-1])
150{
151//color([i/numverts, i/numverts, i/numverts])
152color([(i+1)/(numverts), (i+1)/(numverts), (i+1)/(numverts)])
153translate(verts[indices[i]])
154sphere(r=radius, $fn=24);
155}
156}
157
158module display_poly_verts(verts, radius=0.1)
159{
160//echo(verts);
161
162for (vert = verts)
163{
164translate(vert)
165sphere(r=radius, $fn=24);
166}
167}
168
169//=======================================
170// POLYHEDRON
171//=======================================
172module test_polyhedron()
173{
174//test_polyhedron(tetrahedron(1));
175//test_polyhedron(hexahedron(1));
176//test_polyhedron(octahedron(1));
177//test_polyhedron(dodecahedron(1));
178//test_polyhedron(icosahedron(1));
179//test_dodeca();
180//test_icosa();
181
182
183//display_platonics(20);
184
185//rotate(v=[-1,1,0], a=54.7356)
186//display_polyhedron(tetrahedron(20));
187
188//display_polyhedron(hexahedron(20));
189
190//rotate(v=[-1,1,0], a=54.7356)
191//display_polyhedron(octahedron(20));
192
193rotate(v=[-1,1,0], a=54.7356)
194test_polyhedron_too(octahedron(20), circumradius=20, wireframe=true);
195
196//rotate(v=[-1,1,0], a=54.7356)
197//display_polyhedron(icosahedron(20));
198
199//echo("dihedral: ", plat_dihedral(dodeca_sch));
200//echo("dihedral: ", plat_dihedral(hexa_sch));
201
202//rotate(v=[1,0,0], a=plat_dihedral(dodeca_sch)/2) // dihedral
203//display_polyhedron(dodecahedron(20));
204}
205
206module test_polyhedron_too(poly, circumradius=1, wireradius=1, wireframe=false)
207{
208display_poly_verts(poly[0]);
209
210if (wireframe)
211{
212display_polywireframe(poly, radius=wireradius);
213} else
214{
215display_polyhedron(poly);
216}
217
218color([0.5, 0.5, 0.5, 0.4])
219sphere(r=circumradius, $fn=24);
220
221}
222
223//=======================================
224// COMPOUNDS
225//=======================================
226module test_dual()
227{
228difference()
229{
230display_polyhedron(dodecahedron(1));
231display_polyhedron(icosahedron(1));
232}
233}
234
235module test_duals()
236{
237//test_dual();
238//test_dual_cube1(20);
239//test_dual_cube2(20);
240//test_dual_cube3(20);
241
242test_dual_dodeca(20);
243}
244
245module test_dual_cube1(rad=1)
246{
247// Union
248display_polyhedron(hexahedron(rad));
249display_polyhedron(octahedron(rad));
250}
251
252module test_dual_cube2(rad=1)
253{
254// Difference
255difference()
256{
257display_polyhedron(hexahedron(rad));
258display_polyhedron(octahedron(rad));
259}
260}
261
262module test_dual_cube3(rad=1)
263{
264// Intersection, for truncation
265intersection()
266{
267display_polyhedron(hexahedron(rad));
268display_polyhedron(octahedron(rad));
269}
270}
271
272// Calculated by doing trig on a icosahedron with radius 1
273// calculate the distance between any two vertices
274// then use that to find the angles between them
275icosaangle = 63.43;
276
277
278function icosasph(rad=1) = [
279sph(0,0,rad), // top
280
281// Top lesser circle
282sph(72*0, icosaangle, rad), // top
283sph(72*1, icosaangle, rad), // top
284sph(72*2, icosaangle, rad), // top
285sph(72*3, icosaangle, rad), // top
286sph(72*4, icosaangle, rad), // top
287
288// Bottom lesser circle
289sph((72*0)+36, 180-icosaangle,rad), // top
290sph((72*1)+36, 180-icosaangle,rad), // top
291sph((72*2)+36, 180-icosaangle,rad), // top
292sph((72*3)+36, 180-icosaangle,rad), // top
293sph((72*4)+36, 180-icosaangle,rad), // top
294
295sph(0,0,-rad), // bottom
296];
297
298function icosacart(rad=1) = [
299sph_to_cart(icosasph(rad)[0]),
300sph_to_cart(icosasph(rad)[1]),
301
302sph_to_cart(icosasph(rad)[2]),
303sph_to_cart(icosasph(rad)[3]),
304sph_to_cart(icosasph(rad)[4]),
305sph_to_cart(icosasph(rad)[5]),
306sph_to_cart(icosasph(rad)[6]),
307
308sph_to_cart(icosasph(rad)[7]),
309sph_to_cart(icosasph(rad)[8]),
310sph_to_cart(icosasph(rad)[9]),
311sph_to_cart(icosasph(rad)[10]),
312sph_to_cart(icosasph(rad)[11]),
313];
314
315icosaedges = [
316// Top
317[0,1],
318[0,2],
319[0,3],
320[0,4],
321[0,5],
322
323[1,2],
324[2,3],
325[3,4],
326[4,5],
327[5,1],
328
329// Bottom
330[11,6],
331[11,7],
332[11,8],
333[11,9],
334[11,10],
335
336[6,7],
337[7,8],
338[8,9],
339[9,10],
340[10,6],
341
342// antiprism
343[1,6],
344[2,6],
345
346[2,7],
347[3,7],
348
349[3,8],
350[4,8],
351
352[4,9],
353[5,9],
354
355[5,10],
356[6,10],
357[1,10]
358];
359
360// clockwise winding
361icosafaces = [
362// top
363[0,2,1],
364[0,3,2],
365[0,4,3],
366[0,5,4],
367[0,1,5],
368
369// antiprism
370[1,2,6],
371[2,7,6],
372[2,3,7],
373[3,8,7],
374[3,4,8],
375[4,9,8],
376[4,5,9],
377[5,10,9],
378[1,10,5],
379[1,6,10],
380
381// bottom
382[11,6,7],
383[11,7,8],
384[11,8,9],
385[11,9,10],
386[11,10,6],
387];
388
389
390function icosaplat(rad=1) = [icosacart(rad), icosafaces, icosaedges];
391
392module test_dual_dodeca(rad=1)
393{
394inradius = plat_inradius(dodeca_sch, rad);
395
396// echo("rad, inrad: ", rad, inradius);
397echo("Dihedral Icosa: ", plat_dihedral(icosa_sch));
398
399mycosasph = icosasph(inradius);
400mycosacart = [
401sph_to_cart(mycosasph[0]),
402
403sph_to_cart(mycosasph[1]),
404sph_to_cart(mycosasph[2]),
405sph_to_cart(mycosasph[3]),
406sph_to_cart(mycosasph[4]),
407sph_to_cart(mycosasph[5]),
408
409sph_to_cart(mycosasph[6]),
410sph_to_cart(mycosasph[7]),
411sph_to_cart(mycosasph[8]),
412sph_to_cart(mycosasph[9]),
413sph_to_cart(mycosasph[10]),
414
415sph_to_cart(mycosasph[11]),
416];
417
418//mycosa=[mycosacart, ccw_icosafaces, icosaedges];
419mycosa=[mycosacart, icosafaces, icosaedges];
420
421
422//display_poly_verts(icosacart(20), 2.5);
423//display_polywireframe(icosaplat(20), radius=2.5, style=1);
424
425intersection()
426{
427rotate(v=[1,0,0], a=plat_dihedral(dodeca_sch)/2)
428display_polyhedron(dodecahedron(inradius));
429
430//color([0.5,0.5,0.5,0.5])
431rotate(v=[0,0,1], a=90)
432display_polyhedron(mycosa);
433}
434}
435
436
437module test_degrees()
438{
439d1 = deg(25, 17, 16);
440d2 = deg(18,34);
441
442echo("deg: ", d1, " decimal: ", deg_to_dec(d1));
443echo("deg: ", d2, " decimal: ", deg_to_dec(d2));
444}
445
446
447
448
449module test_dodeca()
450{
451echo("TEST_DODECA");
452poly = dodecahedron(20);
453
454//echo(poly);
455
456//verts = poly[0];
457verts = dodeca_cart;
458faces = poly[1];
459
460// difference()
461// {
462// display_polyhedron(poly);
463//
464// cylinder(r=0.5, h=2, center=true, $fn=24);
465// }
466
467
468// display_poly_verts(verts, radius=1);
469//
470color([0/5, 0/5, 0/5, 1])
471polyhedron(points=verts,
472triangles=[
473[0,1,2,3],
474]);
475
476color([2/5, 2/5, 2/5, 1])
477polyhedron(points=verts,
478triangles=[
479[4,5,6,7],
480]);
481
482color([3/5, 3/5, 3/5, 1])
483polyhedron(points=verts,
484triangles=[
485[8,9,10,11],
486]);
487
488color([4/5, 4/5, 4/5, 1])
489polyhedron(points=verts,
490triangles=[
491[12,13,14,15],
492]);
493
494color([5/5, 5/5, 5/5, 1])
495polyhedron(points=verts,
496triangles=[
497[16,17,18,19]
498]);
499
500vertradius = 0.1;
501//display_verts(verts,[0,17,1,9,8], numverts=5, radius=vertradius);
502//display_verts(verts,[1,14,15,2,9], numverts=5, radius=vertradius);
503display_verts(verts,[9,2,16,3,8], numverts=5, radius=vertradius);
504//display_verts(verts,[0,8,3,12,13], numverts=5, radius=vertradius);
505//display_verts(verts,[0,13,4,18,17], numverts=5, radius=vertradius);
506//display_verts(verts,[1,17,18,7,14], numverts=5, radius=1);
507//display_verts(verts,[15,14,7,10,6], numverts=5, radius=1);
508//display_verts(verts,[2,15,6,19,16], numverts=5, radius=1);
509//display_verts(verts,[16,19,5,12,3], numverts=5, radius=1);
510//display_verts(verts,[12,5,11,4,13], numverts=5, radius=1);
511//display_verts(verts,[18,4,11,10,7], numverts=5, radius=1);
512//display_verts(verts,[19,6,10,11,5], numverts=5, radius=1);
513
514// Can't use pentagons directly as they won't
515// have enough precision to be coplanar
516// which will cause CGAL to fail
517color([0.5,0.5,0.5,0.5])
518polyhedron(points=verts,
519triangles=[
520[1,9,8,0,17],
521[9,1,14,15,2],
522[9,2,16,3,8],
523[8,3,12,13,0],
524[0,13,4,18,17],
525[1,17,18,7,14],
526[15,14,7,10,6],
527[2,15,6,19,16],
528[16,19,5,12,3],
529[12,5,11,4,13],
530[18,4,11,10,7],
531[19,6,10,11,5]
532]);
533}
534
535
536//==========================================
537// ICOSAHEDRON
538//==========================================
539module test_icosa()
540{
541poly = icosahedron(10);
542
543verts = poly[0];
544faces = poly[1];
545
546vert1 = verts[faces[0][0]];
547vert2 = verts[faces[0][1]];
548svert1 = sph_from_cart(vert1);
549svert2 = sph_from_cart(vert2);
550distance = sph_dist(svert1, svert2);
551
552echo("vertex1: ", vert1);
553echo("vertex2: ", vert2);
554echo("spherical 1: ", svert1);
555echo("spherical 2: ", svert2);
556
557echo("vertex distance: ", distance);
558icosadihedral = plat_dihedral(icosa_sch);
559echo("Dihedral: ", icosadihedral, 180-icosadihedral);
560echo("Deficiency: ", plat_deficiency(icosa_sch));
561
562// difference()
563// {
564// display_polyhedron(poly);
565//
566// cylinder(r=0.5, h=2, center=true, $fn=24);
567// }
568
569//display_poly_verts(verts);
570
571color([0/5, 0/5, 0/5, 1])
572polyhedron(points=verts,
573triangles=[
574[0,1,2,3],
575]);
576
577color([2/5, 2/5, 2/5, 1])
578polyhedron(points=verts,
579triangles=[
580[4,5,6,7],
581]);
582
583color([3/5, 3/5, 3/5, 1])
584polyhedron(points=verts,
585triangles=[
586[8,9,10,11],
587]);
588
589vertradius = .1;
590//display_verts(verts, [3,0,4], 3, radius = vertradius);
591
592polyhedron(points=verts,
593triangles=[
594[3,0,4],
595[3,4,9],
596[3,9,10],
597[3,10,7],
598[3,7,0],
599[0,8,4],
600[0,7,11],
601[0,11,8],
602[4,8,5],
603[4,5,9],
604[7,10,6],
605[7,6,11],
606[9,5,2],
607[9,2,10],
608[2,6,10],
609[1,5,8],
610[1,8,11],
611[1,11,6],
612[5,1,2],
613[2,1,6]
614]);
615}
616
617