test_ellipsoid_main_axes.py 781 B

1234567891011121314151617181920212223242526272829303132
  1. """Compute main axes of a transformation matrix"""
  2. from vedo import *
  3. settings.default_font = "Calco"
  4. M = np.random.rand(3,3) - 0.5
  5. A = LinearTransform(M)
  6. print(A)
  7. print(M)
  8. p = [1, 2, 3]
  9. pt = Point(p)
  10. print("---------- All these should be equal:")
  11. print("M @ [1,2,3] =", M @ p)
  12. print("A([1,2,3]) =", A(p))
  13. print("A(pt).vertices =", A(pt).vertices[0])
  14. maxes = A.compute_main_axes()
  15. arr1 = Arrow([0,0,0], maxes[0]).c('r', 0.5)
  16. arr2 = Arrow([0,0,0], maxes[1]).c('g', 0.5)
  17. arr3 = Arrow([0,0,0], maxes[2]).c('b', 0.5)
  18. sphere1 = Sphere().wireframe().lighting('off').alpha(0.2)
  19. sphere1.cmap('hot', sphere1.vertices[:,2])
  20. sphere2 = sphere1.clone().apply_transform(A)
  21. show([[sphere1, __doc__],
  22. [sphere2, arr1, arr2, arr3, str(M)]],
  23. N=2, axes=1, bg='bb').close()