voronoi1.py 729 B

1234567891011121314151617181920
  1. """Voronoi convex tiling of the plane from a set of random points"""
  2. import numpy as np
  3. from vedo import Points, show
  4. # Generate a set of random points in the unit square
  5. points = np.random.random((500, 2))
  6. # Create a Voronoi tiling of the plane from a set of points.
  7. pts = Points(points).subsample(0.02) # impose a min distance of 2%
  8. vor = pts.generate_voronoi(padding=0.01)
  9. vor.cmap('Set3', "VoronoiID", on='cells').wireframe(False)
  10. # Create a label for each cell showing its ID
  11. vor.compute_normals() # needed for the labels to face the camera
  12. labels = vor.labels("VoronoiID", on='cells', scale=0.01, justify='center')
  13. # Plot the objects and close the window to continue
  14. show(pts, vor, labels, __doc__, zoom=1.3).close()