transform是Open3D中用于对三维几何形状进行变换的函数。该函数可用于平移、旋转、缩放和刚性变换,支持对点云、网格和体进行变换。
transform(transformation: numpy.ndarray) -> open3d.geometry.Geometry3D
参数:
transformation
: 4x4的变换矩阵,numpy.ndarray类型。返回值:
import open3d as o3d
import numpy as np
# 创建点云对象并进行变换
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(np.random.rand(100, 3))
transformation = np.eye(4)
# 平移
transformation[:3, 3] = [1, 0, 0]
pcd.transform(transformation)
# 旋转
transformation = np.eye(4)
transformation[:3, :3] = [[0, 1, 0], [-1, 0, 0], [0, 0, 1]]
pcd.transform(transformation)
# 缩放
transformation = np.eye(4) / 2
pcd.transform(transformation)
# 创建网格对象并进行变换
mesh = o3d.geometry.TriangleMesh.create_box()
# 刚性变换
transformation = np.eye(4)
transformation[:3, :3] = [[0, 0, 1], [0, 1, 0], [-1, 0, 0]]
mesh.transform(transformation)