1
- // The four non-built-in Platonic solids for OpenSCAD (regular tetrahedron,
2
- // octahedron, dodecahedron and icosahedron).
3
- // By Kalle (http://qalle.net).
1
+ // The non-built-in Platonic solids.
2
+ // See the readme file for the math.
4
3
5
4
module tetrahedron() {
6
5
// regular tetrahedron (centered at origin, edge length 1)
7
- // http://en.wikipedia.org/wiki/Equilateral_triangle
8
- // http://en.wikipedia.org/wiki/Tetrahedron#Regular_tetrahedron
9
6
10
- a = 1 / 2 ; // edge length / 2
11
- b = sqrt (3 ) / 6 ; // radius of incircle of faces
12
- c = sqrt (3 ) / 3 ; // radius of circumcircle of faces
13
- d = sqrt (6 ) / 12 ; // radius of insphere
14
- e = sqrt (6 ) / 4 ; // radius of circumsphere
7
+ he = 1 / 2 ; // half the edge length
8
+ fi = sqrt (3 ) / 6 ; // faces - incircle radius
9
+ fc = sqrt (3 ) / 3 ; // faces - circumcircle radius
10
+ i = sqrt (6 ) / 12 ; // insphere radius
11
+ c = sqrt (6 ) / 4 ; // circumsphere radius
15
12
16
13
polyhedron (
17
14
// vertices
18
15
[
19
- [ 0 , 0 , e ], // 0: top
20
- [ 0 , c , - d ], // 1: bottom front
21
- [- a , - b , - d ], // 2: bottom rear left
22
- [ a , - b , - d ], // 3: bottom rear right
16
+ [ 0 , 0 , c ], // 0: top
17
+ [ 0 , fc , - i ], // 1: bottom front
18
+ [- he , - fi , - i ], // 2: bottom rear left
19
+ [ he , - fi , - i ], // 3: bottom rear right
23
20
],
24
21
// faces
25
22
[
@@ -33,20 +30,19 @@ module tetrahedron() {
33
30
34
31
module octahedron() {
35
32
// regular octahedron (centered at origin, edge length 1)
36
- // http://en.wikipedia.org/wiki/Octahedron#Regular_octahedron
37
33
38
- a = 1 / 2 ; // edge length / 2
39
- b = sqrt (2 ) / 2 ; // radius of circumsphere
34
+ he = 1 / 2 ; // half the edge length
35
+ c = sqrt (2 ) / 2 ; // circumsphere radius
40
36
41
37
polyhedron (
42
38
// vertices
43
39
[
44
- [ 0 , 0 , b ], // 0: top
45
- [- a , a , 0 ], // 1: front left
46
- [ a , a , 0 ], // 2: front right
47
- [ a , - a , 0 ], // 3: rear right
48
- [- a , - a , 0 ], // 4: rear left
49
- [ 0 , 0 , - b ], // 5: bottom
40
+ [ 0 , 0 , c ], // 0: top
41
+ [- he , he , 0 ], // 1: front left
42
+ [ he , he , 0 ], // 2: front right
43
+ [ he , - he , 0 ], // 3: rear right
44
+ [- he , - he , 0 ], // 4: rear left
45
+ [ 0 , 0 , - c ], // 5: bottom
50
46
],
51
47
// faces
52
48
[
@@ -64,45 +60,37 @@ module octahedron() {
64
60
65
61
module dodecahedron() {
66
62
// regular dodecahedron (centered at origin, edge length 1)
67
- // http://en.wikipedia.org/wiki/Regular_dodecahedron
68
- //
69
- // phi = (1 + sqrt(5)) / 2
70
- // phi^2 = phi + 1
71
- //
72
- // if edge = 2/phi, coordinates of vertices are:
73
- // (+-1, +-1, +-1)
74
- // circular permutations of (0, +-phi, +-1/phi)
75
- // to get coordinates with edge length 1, multiply them by phi/2:
76
- // (+-phi/2, +-phi/2, +-phi/2)
77
- // circular permutations of (0, +-(phi+1)/2, +-1/2)
78
63
79
- a = (1 + sqrt (5 )) / 4 ; // phi / 2
80
- b = (3 + sqrt (5 )) / 4 ; // (phi + 1) / 2
81
- c = 1 / 2 ;
64
+ // coordinates of the "cube"
65
+ c = (1 + sqrt (5 )) / 4 ; // phi / 2
66
+ // coordinates of the "rectangular cuboid"
67
+ r1 = 0 ;
68
+ r2 = (3 + sqrt (5 )) / 4 ; // (phi + 1) / 2
69
+ r3 = 1 / 2 ;
82
70
83
71
polyhedron (
84
72
// vertices
85
73
[
86
- [ 0 , b , c ], // 0: front top
87
- [ 0 , b , - c ], // 1: front bottom
88
- [ 0 , - b , c ], // 2: rear top
89
- [ 0 , - b , - c ], // 3: rear bottom
90
- [ c , 0 , b ], // 4: top right
91
- [ c , 0 , - b ], // 5: bottom right
92
- [- c , 0 , b ], // 6: top left
93
- [- c , 0 , - b ], // 7: bottom left
94
- [ a , a , a ], // 8: top front right
95
- [ a , a, - a ], // 9: bottom front right
96
- [ a, - a , a ], // 10: top rear right
97
- [ a, - a, - a ], // 11: bottom rear right
98
- [- a , a , a ], // 12: top front left
99
- [- a , a, - a ], // 13: bottom front left
100
- [- a, - a , a ], // 14: top rear left
101
- [- a, - a, - a ], // 15: bottom rear left
102
- [ b , c , 0 ], // 16: right front
103
- [ b , - c , 0 ], // 17: right rear
104
- [- b , c , 0 ], // 18: left front
105
- [- b , - c , 0 ], // 19: left rear
74
+ [ r1 , r2 , r3 ], // 0: front top
75
+ [ r1 , r2 , - r3 ], // 1: front bottom
76
+ [ r1 , - r2 , r3 ], // 2: rear top
77
+ [ r1 , - r2 , - r3 ], // 3: rear bottom
78
+ [ r3 , r1 , r2 ], // 4: top right
79
+ [ r3 , r1 , - r2 ], // 5: bottom right
80
+ [- r3 , r1 , r2 ], // 6: top left
81
+ [- r3 , r1 , - r2 ], // 7: bottom left
82
+ [ c , c , c ], // 8: top front right
83
+ [ c , c, - c ], // 9: bottom front right
84
+ [ c, - c , c ], // 10: top rear right
85
+ [ c, - c, - c ], // 11: bottom rear right
86
+ [ - c , c , c ], // 12: top front left
87
+ [ - c , c, - c ], // 13: bottom front left
88
+ [ - c, - c , c ], // 14: top rear left
89
+ [ - c, - c, - c ], // 15: bottom rear left
90
+ [ r2 , r3 , r1 ], // 16: right front
91
+ [ r2 , - r3 , r1 ], // 17: right rear
92
+ [- r2 , r3 , r1 ], // 18: left front
93
+ [- r2 , - r3 , r1 ], // 19: left rear
106
94
],
107
95
// faces
108
96
[
@@ -124,29 +112,26 @@ module dodecahedron() {
124
112
125
113
module icosahedron() {
126
114
// regular icosahedron (centered at origin, edge length 1)
127
- // http://en.wikipedia.org/wiki/Regular_icosahedron
128
115
129
- // coordinates of vertices:
130
- // circular permutations of 0, +-1/2, +-phi/2
131
-
132
- a = 1 / 2 ;
133
- b = (1 + sqrt (5 )) / 4 ; // phi/2
116
+ c1 = 0 ; // coordinate 1
117
+ c2 = 1 / 2 ; // coordinate 2
118
+ c3 = (1 + sqrt (5 )) / 4 ; // coordinate 3; phi / 2
134
119
135
120
polyhedron (
136
121
// vertices
137
122
[
138
- [ b , 0 , a ], // 0: right top
139
- [ b , 0 , - a ], // 1: right bottom
140
- [- b , 0 , a ], // 2: left top
141
- [- b , 0 , - a ], // 3: left bottom
142
- [ a , b , 0 ], // 4: front right
143
- [ a , - b , 0 ], // 5: rear right
144
- [- a , b , 0 ], // 6: front left
145
- [- a , - b , 0 ], // 7: rear left
146
- [ 0 , a , b ], // 8: top front
147
- [ 0 , a , - b ], // 9: bottom front
148
- [ 0 , - a , b ], // 10: top rear
149
- [ 0 , - a , - b ], // 11: bottom rear
123
+ [ c3 , c1 , c2 ], // 0: right top
124
+ [ c3 , c1 , - c2 ], // 1: right bottom
125
+ [- c3 , c1 , c2 ], // 2: left top
126
+ [- c3 , c1 , - c2 ], // 3: left bottom
127
+ [ c2 , c3 , c1 ], // 4: front right
128
+ [ c2 , - c3 , c1 ], // 5: rear right
129
+ [- c2 , c3 , c1 ], // 6: front left
130
+ [- c2 , - c3 , c1 ], // 7: rear left
131
+ [ c1 , c2 , c3 ], // 8: top front
132
+ [ c1 , c2 , - c3 ], // 9: bottom front
133
+ [ c1 , - c2 , c3 ], // 10: top rear
134
+ [ c1 , - c2 , - c3 ], // 11: bottom rear
150
135
],
151
136
// faces
152
137
[
0 commit comments