distance2mesh.py 678 B

123456789101112131415161718
  1. """Compute the (signed) distance of one mesh to another"""
  2. from vedo import Sphere, Cube, show
  3. # Create a sphere object and position it at (10,20,30)
  4. s1 = Sphere().pos(10,20,30)
  5. # Create a cube object with color grey and scaled
  6. # along the x-axis by 2, and positioned at (14,20,30)
  7. s2 = Cube(c='grey4').scale([2,1,1]).pos(14,20,30)
  8. # Compute the Euclidean distance between the 2 surfaces
  9. # and set the color of the sphere based on the distance
  10. s1.distance_to(s2, signed=False)
  11. s1.cmap('hot').add_scalarbar('Signed\nDistance')
  12. # Show the sphere, the cube, the script docstring, axes,
  13. # then close the window
  14. show(s1, s2, __doc__ , axes=1, size=(1000,500), zoom=1.5).close()