openjscad-aurora-webapp

Форк
0
483 строки · 10.1 Кб
1
include <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
20
tetra_sch = [3,3];
21
hexa_sch = [4,3];
22
octa_sch = [3,4];
23
dodeca_sch = [5,3];
24
icosa_sch = [3,5];
25

26
// Given the schlafli representation, calculate
27
// the number of edges, vertices, and faces for the solid
28
function plat_edges(pq) = (2*pq[0]*pq[1])/
29
	((2*pq[0])-(pq[0]*pq[1])+(2*pq[1]));
30
function plat_vertices(pq) = (2*plat_edges(pq))/pq[1];
31
function 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]);
38
function plat_deficiency(pq) = DEGREES(2*Cpi - pq[1]*Cpi*(1-2/pq[0]));
39

40
function plat_dihedral(pq) = 2 * asin( cos(180/pq[1])/sin(180/pq[0]));
41

42
function plat_circumradius(pq, a) = 
43
	(a/2)*
44
	tan(Cpi/pq[1])*
45
	tan(plat_dihedral(pq)/2);
46

47
function plat_midradius(pq, a) = 
48
	(a/2)*
49
	cot(Cpi/pq[0])*
50
	tan(plat_dihedral(pq)/2);
51

52
function plat_inradius(pq,a) = 
53
	a/(2*tan(DEGREES(Cpi/pq[0])))*
54
	sqrt((1-cos(plat_dihedral(pq)))/(1+cos(plat_dihedral(pq))));
55

56
//================================================
57
//	Tetrahedron
58
//================================================
59
tetra_cart = [
60
	[+1, +1, +1],
61
	[-1, -1, +1],
62
	[-1, +1, -1],
63
	[+1, -1, -1]
64
];
65

66
function tetra_unit(rad=1) = [
67
	sph_to_cart(sphu_from_cart(tetra_cart[0], rad)), 
68
	sph_to_cart(sphu_from_cart(tetra_cart[1], rad)),
69
	sph_to_cart(sphu_from_cart(tetra_cart[2], rad)),
70
	sph_to_cart(sphu_from_cart(tetra_cart[3], rad)),
71
	];
72

73

74
tetrafaces = [
75
	[0, 3, 1],
76
	[0,1,2],
77
	[2,1,3],
78
	[0,2,3]
79
];
80

81
tetra_edges = [
82
	[0,1],
83
	[0,2],
84
	[0,3], 
85
	[1,2], 
86
	[1,3], 
87
	[2,3],	
88
	];
89

90
function 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
97
hexa_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

108
function hexa_unit(rad=1) = [
109
	sph_to_cart(sphu_from_cart(hexa_cart[0], rad)), 
110
	sph_to_cart(sphu_from_cart(hexa_cart[1], rad)),
111
	sph_to_cart(sphu_from_cart(hexa_cart[2], rad)),
112
	sph_to_cart(sphu_from_cart(hexa_cart[3], rad)),
113
	sph_to_cart(sphu_from_cart(hexa_cart[4], rad)), 
114
	sph_to_cart(sphu_from_cart(hexa_cart[5], rad)), 
115
	sph_to_cart(sphu_from_cart(hexa_cart[6], rad)),
116
	sph_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
122
hexafaces = [
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

131
hexa_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

148
function hexahedron(rad=1) =[hexa_unit(rad), hexafaces, hexa_edges];
149

150

151
//================================================
152
//	Octahedron 
153
//================================================
154

155
octa_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

164
function octa_unit(rad=1) = [
165
	sph_to_cart(sphu_from_cart(octa_cart[0], rad)), 
166
	sph_to_cart(sphu_from_cart(octa_cart[1], rad)),
167
	sph_to_cart(sphu_from_cart(octa_cart[2], rad)),
168
	sph_to_cart(sphu_from_cart(octa_cart[3], rad)),
169
	sph_to_cart(sphu_from_cart(octa_cart[4], rad)), 
170
	sph_to_cart(sphu_from_cart(octa_cart[5], rad)), 
171
	];
172

173
octafaces = [
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

184
octa_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

199
function 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

209
dodeca_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

236
function dodeca_unit(rad=1) = [
237
	sph_to_cart(sphu_from_cart(dodeca_cart[0], rad)), 
238
	sph_to_cart(sphu_from_cart(dodeca_cart[1], rad)),
239
	sph_to_cart(sphu_from_cart(dodeca_cart[2], rad)),
240
	sph_to_cart(sphu_from_cart(dodeca_cart[3], rad)),
241
	sph_to_cart(sphu_from_cart(dodeca_cart[4], rad)), 
242
	sph_to_cart(sphu_from_cart(dodeca_cart[5], rad)), 
243
	sph_to_cart(sphu_from_cart(dodeca_cart[6], rad)),
244
	sph_to_cart(sphu_from_cart(dodeca_cart[7], rad)),
245
	sph_to_cart(sphu_from_cart(dodeca_cart[8], rad)),
246
	sph_to_cart(sphu_from_cart(dodeca_cart[9], rad)), 
247
	sph_to_cart(sphu_from_cart(dodeca_cart[10], rad)), 
248
	sph_to_cart(sphu_from_cart(dodeca_cart[11], rad)),
249
	sph_to_cart(sphu_from_cart(dodeca_cart[12], rad)),
250
	sph_to_cart(sphu_from_cart(dodeca_cart[13], rad)),
251
	sph_to_cart(sphu_from_cart(dodeca_cart[14], rad)), 
252
	sph_to_cart(sphu_from_cart(dodeca_cart[15], rad)), 
253
	sph_to_cart(sphu_from_cart(dodeca_cart[16], rad)),
254
	sph_to_cart(sphu_from_cart(dodeca_cart[17], rad)),
255
	sph_to_cart(sphu_from_cart(dodeca_cart[18], rad)),
256
	sph_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
//	];
279
dodeca_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

329
dodeca_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

370
function 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

380
icosa_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

397
function icosa_sph(rad=1) = [
398
	sphu_from_cart(icosa_cart[0], rad), 
399
	sphu_from_cart(icosa_cart[1], rad),
400
	sphu_from_cart(icosa_cart[2], rad),
401
	sphu_from_cart(icosa_cart[3], rad),
402
	sphu_from_cart(icosa_cart[4], rad), 
403
	sphu_from_cart(icosa_cart[5], rad), 
404
	sphu_from_cart(icosa_cart[6], rad),
405
	sphu_from_cart(icosa_cart[7], rad),
406
	sphu_from_cart(icosa_cart[8], rad),
407
	sphu_from_cart(icosa_cart[9], rad), 
408
	sphu_from_cart(icosa_cart[10], rad), 
409
	sphu_from_cart(icosa_cart[11], rad),
410
	];
411

412
function icosa_unit(rad=1) = [
413
	sph_to_cart(sphu_from_cart(icosa_cart[0], rad)), 
414
	sph_to_cart(sphu_from_cart(icosa_cart[1], rad)),
415
	sph_to_cart(sphu_from_cart(icosa_cart[2], rad)),
416
	sph_to_cart(sphu_from_cart(icosa_cart[3], rad)),
417
	sph_to_cart(sphu_from_cart(icosa_cart[4], rad)), 
418
	sph_to_cart(sphu_from_cart(icosa_cart[5], rad)), 
419
	sph_to_cart(sphu_from_cart(icosa_cart[6], rad)),
420
	sph_to_cart(sphu_from_cart(icosa_cart[7], rad)),
421
	sph_to_cart(sphu_from_cart(icosa_cart[8], rad)),
422
	sph_to_cart(sphu_from_cart(icosa_cart[9], rad)), 
423
	sph_to_cart(sphu_from_cart(icosa_cart[10], rad)), 
424
	sph_to_cart(sphu_from_cart(icosa_cart[11], rad)),
425
	];
426

427
icosa_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

450
icosa_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

483
function icosahedron(rad=1) = [icosa_unit(rad), icosa_faces, icosa_edges];
484

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.