platonicsolids

Platonic solids in Tikz
git clone https://git.tronto.net/platonicsolids
Download | Log | Files | Refs | README

coord.py (1103B)


      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)