Improved example diamonds.py
[linpy.git] / examples / diamonds.py
1 #!/usr/bin/env python3
2
3 import matplotlib.pyplot as plt
4
5 from matplotlib import pylab
6 from mpl_toolkits.mplot3d import Axes3D
7
8 from pypol import *
9
10 x, y, z = symbols('x y z')
11
12 fig = plt.figure()
13
14 diam_plot = fig.add_subplot(2, 2, 1)
15 diam_plot.set_title('Diamond')
16 diam_plot.set_xlim(-1, 1)
17 diam_plot.set_ylim(-1, 1)
18 diam = Ge(y, x - 1) & Le(y, x + 1) & Ge(y, -x - 1) & Le(y, -x + 1)
19 diam.plot(diam_plot, fill=True, edgecolor='red', facecolor='yellow')
20
21 cham_plot = fig.add_subplot(2, 2, 2, projection='3d')
22 cham_plot.set_title('Chamfered cube')
23 cham_plot.set_xlim(0, 3)
24 cham_plot.set_ylim(0, 3)
25 cham_plot.set_zlim(0, 3)
26 cham = Le(0, x) & Le(x, 3) & Le(0, y) & Le(y, 3) & Le(0, z) & Le(z, 3) & \
27 Le(z - 2, x) & Le(x, z + 2) & Le(1 - z, x) & Le(x, 5 - z) & \
28 Le(z - 2, y) & Le(y, z + 2) & Le(1 - z, y) & Le(y, 5 - z) & \
29 Le(y - 2, x) & Le(x, y + 2) & Le(1 - y, x) & Le(x, 5 - y)
30 cham.plot(cham_plot, facecolors=(1, 0, 0, 0.75))
31
32 rhom_plot = fig.add_subplot(2, 2, 3, projection='3d')
33 rhom_plot.set_title('Rhombicuboctahedron')
34 rhom_plot.set_xlim(0, 3)
35 rhom_plot.set_ylim(0, 3)
36 rhom_plot.set_zlim(0, 3)
37 rhom = cham & \
38 Le(x + y + z, 7) & Ge(-2, -x - y - z) & \
39 Le(-1, x + y - z) & Le(x + y - z, 4) & \
40 Le(-1, x - y + z) & Le(x - y + z, 4) & \
41 Le(-1, -x + y + z) & Le(-x + y + z, 4)
42 rhom.plot(rhom_plot, facecolors=(0, 1, 0, 0.75))
43
44 cubo_plot = fig.add_subplot(2, 2, 4, projection='3d')
45 cubo_plot.set_title('Truncated cuboctahedron')
46 cubo_plot.set_xlim(0, 5)
47 cubo_plot.set_ylim(0, 5)
48 cubo_plot.set_zlim(0, 5)
49 cubo = Le(0, x) & Le(x, 5) & Le(0, y) & Le(y, 5) & Le(0, z) & Le(z, 5) & \
50 Le(x -4, y) & Le(y, x + 4) & Le(-x + 1, y) & Le(y, -x + 9) & \
51 Le(y -4, z) & Le(z, y + 4) & Le(-y + 1, z) & Le(z, -y + 9) & \
52 Le(z -4, x) & Le(x, z + 4) & Le(-z + 1, x) & Le(x, -z + 9) & \
53 Le(3, x + y + z) & Le(x + y + z, 12) & \
54 Le(-2, x - y + z) & Le(x - y + z, 7) & \
55 Le(-2, -x + y + z) & Le(-x + y + z, 7) & \
56 Le(-2, x + y - z) & Le(x + y - z, 7)
57 cubo.plot(cubo_plot, facecolors=(0, 0, 1, 0.75))
58 pylab.show()