How to use distance3d.containment_test.points_in_box? #89
-
I just learned about this python library and it's great! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi, as the docstring says, it's a 4x4 numpy array. It is organized as follows:
All components with R belong to the rotation matrix and all components with t to the translation vector. box2origin represents the pose of the box center frame in the origin frame. This is the same as an active transformation of points from box frame to the origin frame. The function will do exactly what you want to do. |
Beta Was this translation helpful? Give feedback.
-
I made an example that took 0.011s to calculate 100000 points, very good results! import numpy as np
from scipy.spatial.transform import Rotation as R
import distance3d.containment_test
# Example
from pyinstrument import Profiler
profiler = Profiler()
profiler.start()
point_cloud = np.random.randn(100000, 3) * 2 # rand point
box_center = np.array([1, 1, 1]) # center point
box_size = np.array([2, 2, 2]) # size
box_rotation = R.from_euler('xyz', [0, 0, 45], degrees=True).as_matrix() # Rotation Z 45deg
box_matrix = np.vstack((np.hstack((box_rotation, box_center.reshape(3, 1))), np.array([0, 0, 0, 1])))
print(box_matrix)
# fitter
points_in_box = distance3d.containment_test.points_in_box(point_cloud, box_matrix, box_size)
point_cloud = point_cloud[points_in_box]
print(point_cloud.shape)
profiler.stop()
profiler.print()
with open("profiler.html", "w") as f:
f.write(profiler.output_html())
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(point_cloud[:,0], point_cloud[:,1], point_cloud[:,2], c='r', marker='o')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()
|
Beta Was this translation helpful? Give feedback.
Hi, as the docstring says, it's a 4x4 numpy array. It is organized as follows:
All components with R belong to the rotation matrix and all components with t to the translation vector.
box2origin represents the pose of the box center frame in the origin frame. This is the same as an active transformation of points from box frame to the origin frame.
The function will do exactly what you want to do.