对Open3D中的三维几何体进行旋转变换。
rotate(self, R: np.ndarray, center: Optional[np.ndarray] = None)
R: np.ndarray
:旋转矩阵,shape应该是 (3, 3)
的矩阵。center: Optional[np.ndarray] = None
:旋转中心,是一个三元素向量。如果没有指定,则会默认计算该几何体的重心作为旋转中心。该函数没有返回值,而是直接对输入的三维几何体进行了旋转变换。
以下示例展示了如何将Open3D中的 TriangleMesh
沿着 Y 轴旋转 90 度。
import open3d as o3d
import numpy as np
mesh = o3d.geometry.TriangleMesh.create_sphere(radius=1)
rotate_angle = np.pi / 2
rotate_axis = np.array([0.0, 1.0, 0.0])
rotation_matrix = np.dot(o3d.geometry.get_rotation_matrix_from_axis_angle(rotate_axis, rotate_angle), np.eye(4)[:3, :3])
mesh.rotate(rotation_matrix)
o3d.visualization.draw_geometries([mesh])
首先通过 get_rotation_matrix_from_axis_angle()
函数计算出变换矩阵,然后通过旋转矩阵调用 Open3D 的 transform()
函数实现了旋转变换。其中,旋转中心可以通过 mesh.get_center()
计算得到。
R
必须是一个维度为 (3, 3)
的矩阵。center
应该是一个三元素向量,否则程序会报错。