File: platonic.cc

package info (click to toggle)
voro%2B%2B 0.4.6%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,372 kB
  • sloc: cpp: 6,384; perl: 232; makefile: 164
file content (86 lines) | stat: -rw-r--r-- 1,731 bytes parent folder | download | duplicates (7)
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
// Platonic solids example code
//
// Author   : Chris H. Rycroft (LBL / UC Berkeley)
// Email    : chr@alum.mit.edu
// Date     : August 30th 2011

#include "voro++.hh"
using namespace voro;

// Golden ratio constants
const double Phi=0.5*(1+sqrt(5.0));
const double phi=0.5*(1-sqrt(5.0));

int main() {
	voronoicell v;

	// Create a tetrahedron
	v.init(-2,2,-2,2,-2,2);
	v.plane(1,1,1);
	v.plane(1,-1,-1);
	v.plane(-1,1,-1);
	v.plane(-1,-1,1);

	v.draw_gnuplot(0,0,0,"tetrahedron.gnu");

	// Create a cube. Since this is the default shape
	// we don't need to do any plane cutting.
	v.init(-1,1,-1,1,-1,1);
	v.draw_gnuplot(0,0,0,"cube.gnu");

	// Create an octahedron
	v.init(-2,2,-2,2,-2,2);
	v.plane(1,1,1);
	v.plane(-1,1,1);
	v.plane(1,-1,1);
	v.plane(-1,-1,1);
	v.plane(1,1,-1);
	v.plane(-1,1,-1);
	v.plane(1,-1,-1);
	v.plane(-1,-1,-1);

	v.draw_gnuplot(0,0,0,"octahedron.gnu");

	// Create a dodecahedron
	v.init(-2,2,-2,2,-2,2);
	v.plane(0,Phi,1);
	v.plane(0,-Phi,1);
	v.plane(0,Phi,-1);
	v.plane(0,-Phi,-1);
	v.plane(1,0,Phi);
	v.plane(-1,0,Phi);
	v.plane(1,0,-Phi);
	v.plane(-1,0,-Phi);
	v.plane(Phi,1,0);
	v.plane(-Phi,1,0);
	v.plane(Phi,-1,0);
	v.plane(-Phi,-1,0);

	v.draw_gnuplot(0,0,0,"dodecahedron.gnu");

	// Create an icosahedron
	v.init(-2,2,-2,2,-2,2);
	v.plane(1,1,1);
	v.plane(-1,1,1);
	v.plane(1,-1,1);
	v.plane(-1,-1,1);
	v.plane(1,1,-1);
	v.plane(-1,1,-1);
	v.plane(1,-1,-1);
	v.plane(-1,-1,-1);
	v.plane(0,phi,Phi);
	v.plane(0,phi,-Phi);
	v.plane(0,-phi,Phi);
	v.plane(0,-phi,-Phi);
	v.plane(Phi,0,phi);
	v.plane(Phi,0,-phi);
	v.plane(-Phi,0,phi);
	v.plane(-Phi,0,-phi);
	v.plane(phi,Phi,0);
	v.plane(phi,-Phi,0);
	v.plane(-phi,Phi,0);
	v.plane(-phi,-Phi,0);

	v.draw_gnuplot(0,0,0,"icosahedron.gnu");

}