drag_chain.py 752 B

12345678910111213141516171819202122232425262728
  1. """Forward kinematics: hover the mouse to drag the chain"""
  2. from vedo import Plotter, versor, Plane, Line
  3. n = 15 # number of points
  4. l = 3 # length of one segment
  5. def func(evt):
  6. if not evt.object:
  7. return
  8. coords = line.points
  9. coords[0] = evt.picked3d
  10. for i in range(1, n):
  11. v = versor(coords[i] - coords[i-1])
  12. coords[i] = coords[i-1] + v * l
  13. line.points = coords # update positions
  14. nodes.points = coords
  15. plt.render()
  16. surf = Plane(s=[60, 60])
  17. line = Line([l*n/2, 0], [-l*n/2, 0], res=n, lw=12)
  18. line.render_lines_as_tubes()
  19. nodes= line.clone().c('red3').point_size(15)
  20. plt = Plotter()
  21. plt.add_callback("on mouse move please call", func)
  22. plt.show(surf, line, nodes, __doc__, zoom=1.3)
  23. plt.close()