该函数用于生成旋转矩阵,以便通过绕给定轴的给定角度进行三维旋转。
def get_rotation_matrix_from_axis_angle(axis: np.ndarray, angle: float) -> np.ndarray:
...
import open3d as o3d
import numpy as np
# 创建三维点云
points = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]]
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(points)
# 绕z轴旋转45度的变换矩阵
R = o3d.geometry.get_rotation_matrix_from_axis_angle([0, 0, 1], 45)
# 应用旋转矩阵,将点云绕z轴旋转45度
pcd.rotate(R, center=(0,0,0))
# 可视化结果
o3d.visualization.draw_geometries([pcd])