Guest User

Untitled

a guest
May 14th, 2020
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1.     #!/usr/bin/env python
  2.     # -*- coding: utf-8 -*-
  3.  
  4.     import numpy as np
  5.     import matplotlib.pyplot as plt
  6.     import itertools
  7.  
  8.     def get_points(a, nmax, theta_min=None, theta_max=None, remove_center=True):
  9.         uvecs = np.array([[1, 0], [0.5, np.sqrt(3)/2.]])
  10.         i = np.arange(-nmax, nmax+1)
  11.         I, J = [thing.flatten() for thing in np.meshgrid(i, i)]
  12.         keep = np.abs(I + J) <= nmax
  13.         if remove_center:
  14.             keep *= (~((I == 0) * (J == 0)))
  15.         pairs = np.stack([thing[keep] for thing in (I, J)], axis=1)
  16.         upoints = (pairs[..., None] * uvecs).sum(axis=1)
  17.         thetas = np.arctan2(upoints[:, 1], upoints[:, 0])
  18.         keep = np.ones_like(thetas, dtype=bool)
  19.         if theta_min != None:
  20.             keep *= thetas >= (np.pi/180) * theta_min
  21.         if theta_max != None:
  22.             keep *= thetas <= (np.pi/180) * theta_max
  23.         return a * upoints[keep], pairs[keep]
  24.  
  25.     r3o2 = np.sqrt(3)/2.
  26.     a, nmax = 1.0, 10
  27.  
  28.     all_points, all_pairs = get_points(a=a, nmax=nmax)
  29.     points, pairs = get_points(a=a, nmax=nmax, theta_min=-0.01, theta_max=30.01)
  30.  
  31.     if True:
  32.         fig = plt.figure()
  33.         ax = fig.add_subplot(1, 1, 1)
  34.         x, y = all_points.T
  35.         ax.plot(x, y, '.k')
  36.         x, y = points.T
  37.         ax.plot(x, y, 'or')
  38.         ax.plot([0, nmax*a], [0, 0], '-b')
  39.         ax.plot([0, nmax*a*r3o2], [0, nmax*a*0.5], '-b')
  40.         ax.set_aspect('equal')
  41.         ax.axes.xaxis.set_visible(False)
  42.         ax.axes.yaxis.set_visible(False)
  43.         plt.show()
Advertisement
Add Comment
Please, Sign In to add comment