Guest User

Untitled

a guest
Apr 11th, 2016
53
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. N = 30                              # number of points to generate
  9. points = np.random.rand(N, 2) * 10  # point locations
  10. radii = np.ones((N,)) * 0.01        # point radii ("weights")
  11.  
  12. def plotvor(cells):
  13.     plt.figure()
  14.     plt.xlim((0,10))
  15.     plt.ylim((0,10))
  16.     plt.hold(True)
  17.     for cell in cells:
  18.         plt.scatter(cell["original"][0], cell["original"][1])
  19.         vertices = np.array(cell["vertices"])
  20.         vertices = np.concatenate((vertices,
  21.             cell["vertices"][0].reshape((1,2))))
  22.         plt.plot(vertices[:,0], vertices[:,1], 'b-')
  23.     plt.show()
  24.  
  25. cells = pyvoro.compute_2d_voronoi(
  26.     points,
  27.     [[0.0, 10.0], [0.0, 10.0]], # box size
  28.     0.5,                        # block size
  29.     radii = radii)
  30.  
  31. plotvor(cells)
RAW Paste Data