Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # install requirements
- # sudo pip install numpy matplotlib pyvoro
- import pyvoro
- import numpy as np
- import matplotlib.pyplot as plt
- points = np.array([[-100,30],
- [-90, 40],
- [-110, 50]])
- radii = np.array([8,
- 7,
- 10])
- xlim = [-124, -71]
- ylim = [ 25 , 53]
- def plotvor(cells, points, radii, xlim, ylim):
- plt.figure()
- plt.hold(True)
- plt.xlim(xlim)
- plt.ylim(ylim)
- for cell in cells:
- plt.scatter(cell["original"][0], cell["original"][1])
- vertices = np.array(cell["vertices"])
- vertices = np.concatenate((vertices,
- cell["vertices"][0].reshape((1,2))))
- plt.plot(vertices[:,0], vertices[:,1], 'b-')
- for point, radius in zip(points, radii):
- t = np.concatenate((np.arange(0, 2*np.pi, 0.1), np.array([0])))
- plt.plot(radius*np.cos(t)+point[0], radius*np.sin(t)+point[1])
- plt.show()
- cells = pyvoro.compute_2d_voronoi(
- points,
- [xlim, ylim], # box size
- 0.5, # block size
- radii = radii)
- plotvor(cells, points, radii, xlim, ylim)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement