align3.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. """Generate 3 random sets of points
  2. and align them using Procrustes method"""
  3. from random import uniform as u
  4. from vedo import Plotter, procrustes_alignment, Points
  5. # Define number of points and a randomness factor
  6. N = 15 # number of points
  7. x = 1.0 # add some randomness
  8. # Generate 3 sets of random points
  9. pts1 = [(u(0, x), u(0, x), u(0, x) + i) for i in range(N)]
  10. pts2 = [(u(0, x) + 3, u(0, x) + i / 2 + 2, u(0, x) + i + 1) for i in range(N)]
  11. pts3 = [(u(0, x) + 4, u(0, x) + i / 4 - 3, u(0, x) + i - 2) for i in range(N)]
  12. # Convert the sets of points into Points objects with different colors and sizes
  13. vpts1 = Points(pts1).c("r").ps(8)
  14. vpts2 = Points(pts2).c("g").ps(8)
  15. vpts3 = Points(pts3).c("b").ps(8)
  16. # Perform Procrustes alignment on the sets of points
  17. # and obtain the aligned sets
  18. # return an Assembly object formed by the aligned sets
  19. aligned = procrustes_alignment([vpts1, vpts2, vpts3])
  20. #print([aligned.transform])
  21. # Create a Plotter object with a 1x2 grid, 2D axes,
  22. # and independent camera control
  23. plt = Plotter(shape=[1,2], axes=2, sharecam=False)
  24. plt.at(0).show(vpts1, vpts2, vpts3, __doc__)
  25. plt.at(1).show(aligned)
  26. plt.interactive().close()