Guest User

Untitled

a guest
Apr 11th, 2016
74
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # install requirements
  2. # sudo pip install numpy matplotlib pyvoro
  3.  
  4. import pyvoro
  5. import numpy as np
  6. import matplotlib.pyplot as plt
  7.  
  8. points = np.array([[-100,30],
  9.                    [-90, 40],
  10.                    [-110, 50]])
  11.  
  12. radii = np.array([8,
  13.                   7,
  14.                   10])
  15.  
  16. xlim = [-124, -71]
  17. ylim = [ 25 ,  53]
  18.  
  19. def plotvor(cells, points, radii, xlim, ylim):
  20.     plt.figure()
  21.     plt.hold(True)
  22.     plt.xlim(xlim)
  23.     plt.ylim(ylim)
  24.     for cell in cells:
  25.         plt.scatter(cell["original"][0], cell["original"][1])
  26.         vertices = np.array(cell["vertices"])
  27.         vertices = np.concatenate((vertices,
  28.             cell["vertices"][0].reshape((1,2))))
  29.         plt.plot(vertices[:,0], vertices[:,1], 'b-')
  30.     for point, radius in zip(points, radii):
  31.         t = np.concatenate((np.arange(0, 2*np.pi, 0.1), np.array([0])))
  32.         plt.plot(radius*np.cos(t)+point[0], radius*np.sin(t)+point[1])
  33.     plt.show()
  34.  
  35. cells = pyvoro.compute_2d_voronoi(
  36.     points,
  37.     [xlim, ylim],     # box size
  38.     0.5,              # block size
  39.     radii = radii)
  40.  
  41. plotvor(cells, points, radii, xlim, ylim)
RAW Paste Data