align2.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. """Generate two random sets of points and align
  2. them using the Iterative Closest Point algorithm"""
  3. from random import uniform as u
  4. from vedo import settings, Points, Arrows, Plotter
  5. settings.default_font = "Calco"
  6. N1 = 25 # number of points of first set
  7. N2 = 35 # number of points of second set
  8. x = 1.0 # add some randomness
  9. # Create two sets of random points with different colors
  10. pts1 = [(u(0, x), u(0, x), u(0, x) + i) for i in range(N1)]
  11. pts2 = [(u(0, x)+3, u(0, x)+i/3+2, u(0, x)+i+1) for i in range(N2)]
  12. vpts1 = Points(pts1).ps(10).c("blue5")
  13. vpts2 = Points(pts2).ps(10).c("red5")
  14. # Find best alignment between the 2 sets of Points,
  15. # e.i. find how to move vpts1 to best match vpts2
  16. aligned_pts1 = vpts1.clone().align_to(vpts2, invert=False)
  17. txt = aligned_pts1.transform.__str__()
  18. # Create arrows to visualize how the points move during alignment
  19. arrows = Arrows(pts1, aligned_pts1, s=0.7).c("black")
  20. # Create a plotter with two subplots
  21. plt = Plotter(N=2, axes=1)
  22. plt.at(0).show(__doc__, vpts1, vpts2)
  23. plt.at(1).show(txt, aligned_pts1, arrows, vpts2, viewup="z")
  24. plt.interactive()
  25. plt.close()