Advertisement
Guest User

Untitled

a guest
Nov 10th, 2021
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. def dots(nmax, a=None, rot=None):
  5.     r3o2, to_rads = np.sqrt(3)/2., np.pi/180.
  6.     if a == None: a = 1.0
  7.     if rot == None: rot=0.0
  8.     i = np.arange(-nmax, nmax+1)
  9.     I, J = np.meshgrid(i, i)
  10.     keep = np.abs(I+J) <= nmax
  11.     I, J = [thing[keep].flatten() for thing in (I, J)]
  12.     x, y = a*(I + 0.5*J), a*r3o2*J
  13.     c, s = [f(to_rads*rot) for f in (np.cos, np.sin)]
  14.     return x*c - y*s, y*c + x*s
  15.    
  16. rat = np.sqrt(13./7)
  17.  
  18. A = dots(12)
  19. B, C = dots(10, rat, 5.209), dots(10, rat, 11.218)
  20.  
  21. fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[12, 7.5])
  22. ax1.scatter([0], [0], s=400, c='black', edgecolor='none')
  23. ax1.scatter(A[0], A[1], s=200, c='none', edgecolor='black')
  24. ax1.scatter(B[0], B[1], s=60, c='black', edgecolor='none')
  25. ax1.set_xlim(-0.5, 14)
  26. ax1.set_ylim(-0.5, 14)
  27. ax1.set_aspect('equal')
  28. for i, j in ((1,3), (2,6), (5,2), (9,1), (3,9), (-2, 7), (-1, 10), (-5, 11)):
  29.     x0 = i + j * 0.5
  30.     y0 = j * np.sqrt(3)/2
  31.     ax1.scatter([x0], [y0], c = 'none', edgecolor='red', s=550, lw=2)
  32. i, j = 6, 5
  33. x0 = i + j * 0.5
  34. y0 = j * np.sqrt(3)/2
  35. d, dd = 2, 1.5
  36. ax1.arrow(x0+d, y0+d, -dd, -dd, color='red', width=0.1, head_width=0.5, head_length=0.5)
  37. ax1.set_title('(' + str(i) + ',  '+ str(j) + ') <-> (5, 3) (5.209°)', fontsize=16)
  38.  
  39. ax2.scatter([0], [0], s=400, c='black', edgecolor='none')
  40. ax2.scatter(A[0], A[1], s=200, c='none', edgecolor='black')
  41. ax2.scatter(C[0], C[1], s=60, c='black', edgecolor='none')
  42. ax2.set_xlim(-0.5, 14)
  43. ax2.set_ylim(-0.5, 14)
  44. ax2.set_aspect('equal')
  45. for i, j in ((-6, 11), ):
  46.     x0 = i + j * 0.5
  47.     y0 = j * np.sqrt(3)/2
  48.     ax2.scatter([x0], [y0], c = 'none', edgecolor='red', s=550, lw=2)
  49. i, j = 5, 6
  50. x0 = i + j * 0.5
  51. y0 = j * np.sqrt(3)/2
  52. d, dd = 2, 1.5
  53. ax2.arrow(x0+d, y0+d, -dd, -dd, color='red', width=0.1, head_width=0.5, head_length=0.5)
  54. ax2.set_title('(' + str(i) + ',  '+ str(j) + ') <-> (5, 3) (11.218°)', fontsize=16)
  55. plt.subplots_adjust(left=0.1, right=0.9)
  56. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement