Version 1.0.3
[linpy.git] / examples / tesseract.py
1 #!/usr/bin/env python3
2
3 # In geometry, the tesseract is the four-dimensional analog of the cube; the
4 # tesseract is to the cube as the cube is to the square. Just as the surface of
5 # the cube consists of 6 square faces, the hypersurface of the tesseract
6 # consists of 8 cubical cells.
7
8 from linpy import Le, symbols
9
10
11 x, y, z, t = symbols('x y z t')
12
13 tesseract = Le(0, x, 1) & Le(0, y, 1) & Le(0, z, 1) & Le(0, t, 1)
14
15
16 def faces(polyhedron):
17 for points in polyhedron.faces():
18 face = points[0].aspolyhedron()
19 face = face.convex_union(*[point.aspolyhedron()
20 for point in points[1:]])
21 yield face
22
23
24 if __name__ == '__main__':
25 print('Faces of tesseract\n\n {}\n\nare:\n'.format(tesseract))
26 for face in faces(tesseract):
27 assert(len(face.vertices()) == 8)
28 print(' {}'.format(face))