pca_ellipse.py 697 B

12345678910111213141516171819
  1. """Draw the ellipse (dark) and the ellipsoid (light)
  2. that in both cases contain 50% of a point cloud,
  3. then check how many points are inside both objects"""
  4. from vedo import Points, pca_ellipse, pca_ellipsoid, printc, show
  5. import numpy as np
  6. pts = Points(np.random.randn(1000,3))
  7. pts.scale([2, 1.5, 0.01]).rotate_z(30).pos([50,60,0])
  8. elli2d = pca_ellipse( pts, pvalue=0.5)
  9. elli3d = pca_ellipsoid(pts, pvalue=0.5).alpha(0.1)
  10. extruded = elli2d.z(-0.1).extrude(0.2) # make an oval box
  11. printc("Inside ellipse :", extruded.inside_points(pts).npoints, c='b')
  12. printc("Inside ellipsoid:", elli3d.inside_points(pts).npoints, c='b')
  13. show(pts, elli2d, elli3d, __doc__, axes=1, zoom='tight').close()