spline_ease.py 857 B

123456789101112131415161718192021222324252627
  1. """Spline three points in space"""
  2. from vedo import *
  3. pts = [[0,0,0],
  4. [0.5,0.6,0.8],
  5. [1,1,1]]
  6. gpts = Points(pts, r=10).c('green',0.5)
  7. # Create a spline where the final points are more dense (easing)
  8. line = Spline(pts, easing="OutCubic", res=100)
  9. vpts = line.clone().point_size(3).shift(0,0.1,0) # a dotted copy
  10. # Calculate positions as a fraction of the length of the line,
  11. # being x=0 the first point and x=1 the last point.
  12. # This corresponds to an imaginary point that travels along the line
  13. # at constant speed:
  14. equi_pts = Points([line.eval(x) for x in np.arange(0,1, 0.1)]).c('blue')
  15. redpt = Point(r=25).c('red')
  16. plt = show(vpts, gpts, line, redpt, equi_pts, axes=1, interactive=0)
  17. # Animation
  18. pts = line.points
  19. for i in range(line.npoints):
  20. redpt.pos(pts[i]) # assign the new position
  21. plt.render()
  22. plt.interactive().close()