前提:固定系欧拉角,旋转顺序XYZ
直接用py文件简单计算:
from scipy.spatial.transform import Rotation
import numpy as np
def calculate_euler_angles(vec1, vec2, rotation_order='xyz'):
# 将法向量转换为单位向量
vec1_normalized = vec1 / np.linalg.norm(vec1)
vec2_normalized = vec2 / np.linalg.norm(vec2)
# 计算旋转轴(叉积)
axis = np.cross(vec1_normalized, vec2_normalized)
new_axis = axis / np.linalg.norm(axis)
# 计算旋转角度(夹角)
dot_product = np.dot(vec1_normalized, vec2_normalized)
angle = np.arccos(dot_product)
# 创建 Rotation 对象
rotation = Rotation.from_rotvec(angle * new_axis)
# 获取固定欧拉角
euler_angles = rotation.as_euler(rotation_order, degrees=True)
# 输出欧拉角
print(f"Euler Angles ({rotation_order}): {euler_angles}")
# 两个法向量,这里使用示例值
vec1 = np.array([0.0003243, -0.0055068, 0.999985]) # src
vec2 = np.array([0.0000204, -0.0055769, 0.9999844]) # dst
# 按照 xyz 欧拉角顺序计算欧拉角
calculate_euler_angles(vec1, vec2, rotation_order='xyz')