pysdic.PointCloud.frame_transform#
- PointCloud.frame_transform(input_frame=None, output_frame=None, inplace=False)[source]#
Transform the point cloud from an input frame of reference to an output frame of reference (only for 3D point clouds).
Assuming the point cloud is defined in the coordinate system of the input frame, this method transforms the points to the coordinate system of the output frame.
See also
Package py3dframe for more details on
FrameandFrameTransform.
Warning
This method only works for 3-dimensional point clouds, as frame transformations are defined in 3D space.
- Parameters:
input_frame (Optional[
Frame], optional) – The input frame representing the current coordinate system of the point cloud. If None, the canonical frame is assumed.output_frame (Optional[
Frame], optional) – The output frame representing the target coordinate system for the point cloud. If None, the canonical frame is assumed.inplace (
bool, optional) – IfTrue, modifies the current point cloud in place and returns itself. IfFalse, returns a newPointCloudinstance (default isFalse).
- Returns:
A new
PointCloudobject containing the transformed points in the output frame or the modified current instance ifinplaceisTrue.- Return type:
- Raises:
ValueError – If the input or output frames are not instances of
Frame.
Examples
Create a
PointCloudfrom a random NumPy array.1import numpy as np 2from pysdic import PointCloud 3 4# Create a random point cloud with 100 points 5random_points = np.random.rand(100, 3) # shape (100, 3) 6point_cloud = PointCloud.from_array(random_points)
Lets assume this point cloud is defined in the canonical frame. We want to express the point cloud in local frame defined by a :
orgin at (1, 1, 1)
x-axis along (0, 1, 0)
y-axis along (-1, 0, 0)
z-axis along (0, 0, 1)
We can use the frame_transform method to perform this transformation.
1from py3dframe import Frame 2 3# Define input and output frames 4input_frame = Frame.canonical() 5output_frame = Frame(origin=[1, 1, 1], x_axis=[0, 1, 0], y_axis=[-1, 0, 0], z_axis=[0, 0, 1]) 6 7# Transform the point cloud from input frame to output frame 8transformed_point_cloud = point_cloud.frame_transform(input_frame=input_frame, output_frame=output_frame) 9print(transformed_point_cloud.points) 10# Output: A NumPy array of shape (100, 3) containing the transformed coordinates