Guest User

Untitled

a guest
Jun 6th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 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. plt.figure()
  22. plt.subplot(1, 2, 1)
  23. plt.scatter([0], [0], s=400, c='black', edgecolor='none')
  24. plt.scatter(A[0], A[1], s=200, c='none', edgecolor='black')
  25. plt.scatter(B[0], B[1], s=60, c='black', edgecolor='none')
  26. plt.xlim(-0.5, 14)
  27. plt.ylim(-0.5, 14)
  28. plt.gca().set_aspect('equal')
  29. plt.title('(5, 6) <-> (5, 3) (5.209 deg)', fontsize=16)
  30.  
  31. plt.subplot(1, 2, 2)
  32. plt.scatter([0], [0], s=400, c='black', edgecolor='none')
  33. plt.scatter(A[0], A[1], s=200, c='none', edgecolor='black')
  34. plt.scatter(C[0], C[1], s=60, c='black', edgecolor='none')
  35. plt.xlim(-0.5, 14)
  36. plt.ylim(-0.5, 14)
  37. plt.gca().set_aspect('equal')
  38. plt.title('(6, 5) <-> (5, 3) (11.218 deg)', fontsize=16)
  39.  
  40. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment