Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- def dots(nmax, a=None, rot=None):
- r3o2, to_rads = np.sqrt(3)/2., np.pi/180.
- if a == None: a = 1.0
- if rot == None: rot=0.0
- i = np.arange(-nmax, nmax+1)
- I, J = np.meshgrid(i, i)
- keep = np.abs(I+J) <= nmax
- I, J = [thing[keep].flatten() for thing in (I, J)]
- x, y = a*(I + 0.5*J), a*r3o2*J
- c, s = [f(to_rads*rot) for f in (np.cos, np.sin)]
- return x*c - y*s, y*c + x*s
- rat = np.sqrt(13./7)
- A = dots(12)
- B, C = dots(10, rat, 5.209), dots(10, rat, 11.218)
- fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[12, 7.5])
- ax1.scatter([0], [0], s=400, c='black', edgecolor='none')
- ax1.scatter(A[0], A[1], s=200, c='none', edgecolor='black')
- ax1.scatter(B[0], B[1], s=60, c='black', edgecolor='none')
- ax1.set_xlim(-0.5, 14)
- ax1.set_ylim(-0.5, 14)
- ax1.set_aspect('equal')
- for i, j in ((1,3), (2,6), (5,2), (9,1), (3,9), (-2, 7), (-1, 10), (-5, 11)):
- x0 = i + j * 0.5
- y0 = j * np.sqrt(3)/2
- ax1.scatter([x0], [y0], c = 'none', edgecolor='red', s=550, lw=2)
- i, j = 6, 5
- x0 = i + j * 0.5
- y0 = j * np.sqrt(3)/2
- d, dd = 2, 1.5
- ax1.arrow(x0+d, y0+d, -dd, -dd, color='red', width=0.1, head_width=0.5, head_length=0.5)
- ax1.set_title('(' + str(i) + ', '+ str(j) + ') <-> (5, 3) (5.209°)', fontsize=16)
- ax2.scatter([0], [0], s=400, c='black', edgecolor='none')
- ax2.scatter(A[0], A[1], s=200, c='none', edgecolor='black')
- ax2.scatter(C[0], C[1], s=60, c='black', edgecolor='none')
- ax2.set_xlim(-0.5, 14)
- ax2.set_ylim(-0.5, 14)
- ax2.set_aspect('equal')
- for i, j in ((-6, 11), ):
- x0 = i + j * 0.5
- y0 = j * np.sqrt(3)/2
- ax2.scatter([x0], [y0], c = 'none', edgecolor='red', s=550, lw=2)
- i, j = 5, 6
- x0 = i + j * 0.5
- y0 = j * np.sqrt(3)/2
- d, dd = 2, 1.5
- ax2.arrow(x0+d, y0+d, -dd, -dd, color='red', width=0.1, head_width=0.5, head_length=0.5)
- ax2.set_title('(' + str(i) + ', '+ str(j) + ') <-> (5, 3) (11.218°)', fontsize=16)
- plt.subplots_adjust(left=0.1, right=0.9)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement