diff options
Diffstat (limited to 'coord.py')
| -rwxr-xr-x | coord.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/coord.py b/coord.py new file mode 100755 index 0000000..6fe33f9 --- /dev/null +++ b/coord.py | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | #!/usr/bin/python | ||
| 2 | |||
| 3 | from math import sqrt, sin, cos | ||
| 4 | |||
| 5 | phi = (1.0+sqrt(5.0))/2.0 | ||
| 6 | |||
| 7 | def projcoord(P, alpha, beta): | ||
| 8 | x, y, z = P | ||
| 9 | xnew = x*cos(alpha) + y*sin(alpha) | ||
| 10 | ynew = x*sin(alpha)*sin(beta) - y*cos(alpha)*sin(beta) + z*cos(beta) | ||
| 11 | return xnew, ynew | ||
| 12 | |||
| 13 | def printtikz(shape, alpha, beta): | ||
| 14 | for i in range(len(shape)): | ||
| 15 | x, y = projcoord(shape[i], alpha, beta) | ||
| 16 | print("\coordinate (P" + str(i) + ") at (" + str(x) + ", " + str(y) + ");") | ||
| 17 | |||
| 18 | tetrahedron = [(1,1,1), (1,-1,-1), (-1,1,-1), (-1,-1,1)] | ||
| 19 | |||
| 20 | octahedron = [(1,0,0), (-1,0,0), (0,1,0), (0,-1,0), (0,0,1), (0,0,-1)] | ||
| 21 | |||
| 22 | cube = [(1,1,1), (1,1,-1), (1,-1,1), (1,-1,-1), (-1,1,1), (-1,1,-1), (-1,-1,1), (-1,-1,-1)] | ||
| 23 | |||
| 24 | dodecahedron = cube + [(0,1/phi,phi), (0,1/phi,-phi), (0,-1/phi,phi), (0,-1/phi,-phi), | ||
| 25 | (1/phi,phi,0), (1/phi,-phi,0), (-1/phi,phi,0), (-1/phi,-phi,0), | ||
| 26 | (phi,0,1/phi), (-phi,0,1/phi), (phi,0,-1/phi), (-phi,0,-1/phi)] | ||
| 27 | |||
| 28 | icosahedron = [(0,1,phi), (0,1,-phi), (0,-1,phi), (0,-1,-phi), | ||
| 29 | (1,phi,0), (1,-phi,0), (-1,phi,0), (-1,-phi,0), | ||
| 30 | (phi,0,1), (-phi,0,1), (phi,0,-1), (-phi,0,-1)] | ||
| 31 | |||
| 32 | printtikz(icosahedron, 0.2, 0.2) | ||
