-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpolyhedrons_platon.jscad
112 lines (88 loc) · 2.84 KB
/
polyhedrons_platon.jscad
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
// title : Regular polyhedrons Library (Platonic solids)
// author : Gilbert Duval
// license : MIT License
// revision : 0.001
// tags : polyhedron platon
// file : polyhedrons_platon.jscad
// Data from dmccooey.com/polyhedra
// Library to include with : include("polyhedrons_platon.jscad");
// Instanciate before use with : polyh1();
polyh1 = function () {
polyh1.tetrahedron = function () {
var C0, vertices, faces;
C0 = Math.sqrt(2) / 4;
vertices = [
[ C0, C0, C0],
[-C0, -C0, C0],
[-C0, C0, -C0],
[ C0, -C0, -C0]
];
faces = [
[0, 3, 1],
[0, 1, 2],
[2, 1, 3],
[0, 2, 3]
];
return polyhedron({points:vertices, polygons:faces});
}
polyh1.octahedron = function () {
var C0, vertices, faces;
C0 = 1;
vertices = [
[C0, 0, 0], [-C0, 0, 0], [0, C0, 0],
[0, -C0, 0], [0, 0, C0], [0, 0, -C0]
];
faces = [
[4,2,0],[4,0,3],[4,3,1],[4,1,2],
[5,0,2],[5,3,0],[5,1,3],[5,2,1]
];
return polyhedron({points:vertices, polygons:faces});
}
polyh1.hexahedron = function () {
var vertices, faces;
vertices = [
[0.5, 0.5, 0.5], [-0.5, 0.5, 0.5],
[-0.5, -0.5, 0.5], [0.5, -0.5, 0.5],
[0.5, 0.5, -0.5], [-0.5, 0.5, -0.5],
[-0.5, -0.5, -0.5], [0.5, -0.5, -0.5]
];
faces = [
[0,3,2,1],[0,1,5,4],[1,2,6,5],
[2,3,7,6],[3,0,4,7],[4,5,6,7]
];
return polyhedron({points:vertices, polygons:faces});
}
polyh1.dodecahedron = function () {
var C0, vertices, faces;
C0 = 1.61803399;
vertices = [
[+1, +1, +1], [+1, -1, +1], [-1, -1, +1], [-1, +1, +1],
[+1, +1, -1], [-1, +1, -1], [-1, -1, -1], [+1, -1, -1],
[0, +1/C0, +C0], [0, -1/C0, +C0], [0, -1/C0, -C0], [0, +1/C0, -C0],
[-1/C0, +C0, 0], [+1/C0, +C0, 0], [+1/C0, -C0, 0], [-1/C0, -C0, 0],
[-C0, 0, +1/C0], [+C0, 0, +1/C0], [+C0, 0, -1/C0], [-C0, 0, -1/C0]];
faces = [
[1,9,8], [1,8,0], [1,0,17], [9,1,14], [9,14,15], [9,15,2],
[9,2,16], [9,16,3], [9,3,8], [8,3,12], [8,12,13], [8,13,0],
[0,13,4], [0,4,18], [0,18,17], [1,17,18], [1,18,7], [1,7,14],
[15,14,7], [15,7,10], [15,10,6], [2,15,6], [2,6,19], [2,19,16],
[16,19,5], [16,5,12], [16,12,3], [12,5,11], [12,11,4], [12,4,13],
[18,4,11], [18,11,10], [18,10,7], [19,6,10], [19,10,11], [19,11,5]
];
return polyhedron({points:vertices, polygons:faces});
}
polyh1.icosahedron = function () {
var C0, vertices, faces;
C0 = 1.61803399;
vertices = [
[0, +1, +C0], [0, +1, -C0], [0, -1, -C0], [0, -1, +C0],
[+C0, 0, +1], [+C0, 0, -1], [-C0, 0, -1], [-C0, 0, +1],
[+1, +C0, 0], [+1, -C0, 0], [-1, -C0, 0], [-1, +C0, 0] ];
faces = [
[3,0,4], [3,4,9], [3,9,10], [3,10,7], [3,7,0], [0,8,4], [0,7,11],
[0,11,8], [4,8,5], [4,5,9], [7,10,6], [7,6,11], [9,5,2], [9,2,10],
[2,6,10], [1,5,8], [1,8,11], [1,11,6], [5,1,2], [2,1,6]
];
return polyhedron({points:vertices, polygons:faces});
}
}