fitspheres1.py 947 B

12345678910111213141516171819202122232425262728
  1. """Fit spheres to a region of a surface defined by
  2. N points that are closest to a given point of the surface.
  3. For some of these point we show the fitting sphere.
  4. Red lines join the center of the sphere to the surface point.
  5. Blue points are the N points used for fitting"""
  6. from vedo import *
  7. settings.default_font = 'Kanopus'
  8. settings.use_depth_peeling = True
  9. plt = Plotter()
  10. # load mesh and increase by a lot subdivide(2) the nr of surface vertices
  11. cow = Mesh(dataurl+"cow.vtk").alpha(0.3).subdivide(2)
  12. for i, p in enumerate(cow.points):
  13. if i % 1000:
  14. continue # skip most points
  15. pts = cow.closest_point(p, n=16) # find the n-closest points to p
  16. sph = fit_sphere(pts).alpha(0.05) # find the fitting sphere
  17. if sph is None:
  18. continue # may fail if all points sit on a plane
  19. plt += sph
  20. plt += Points(pts)
  21. plt += Line(sph.center, p, lw=2)
  22. plt += [cow, __doc__]
  23. plt.show(viewup="z", axes=1).close()