坐标变换
2024年11月21日大约 2 分钟
重要
本文内容默认以左手笛卡尔坐标系为基础
虽然右手坐标系更为常见
多维坐标变换
考虑三维空间中的一点 P
此处
变换方程就是
二维坐标变换
公式:
import numpy as np
theta = np.radians(30)
x,y = 5, 3
rotation_matrix = np.array([
[np.cos(theta), np.sin(theta)],
[-np.sin(theta), np.cos(theta)]
])
point = np.array([x,y])
rotation_matrix.dot(point)
array([5.83012702, 0.09807621])
三维坐标变换
左手笛卡尔坐标系
绕x轴公式:
绕y轴公式:
绕z轴公式:
右手笛卡尔坐标系
绕x轴公式:
绕y轴公式:
绕z轴公式:
import numpy as np
alpha = np.radians(30) # 绕z轴旋转
beta = np.radians(30) # 绕y轴旋转
gamma = np.radians(30) # 绕x轴旋转
x, y, z = 3, 4, 5
rotation_matrix_z = np.array([
[np.cos(alpha), np.sin(alpha), 0],
[-np.sin(alpha), np.cos(alpha), 0],
[0, 0, 1]
])
rotation_matrix_y = np.array([
[np.cos(beta), 0, -np.sin(beta)],
[0, 1, 0],
[np.sin(beta), 0, np.cos(beta)]
])
rotation_matrix_x = np.array([
[1, 0, 0],
[0, np.cos(gamma), np.sin(gamma)],
[0, -np.sin(gamma), np.cos(gamma)]
])
point = np.array([x, y, z])
z_transformed_point = rotation_matrix_z.dot(point)
y_transformed_point = rotation_matrix_y.dot(point)
x_transformed_point = rotation_matrix_x.dot(point)
print(z_transformed_point)
print(y_transformed_point)
print(x_transformed_point)
[4.59807621 1.96410162 5. ]
[0.09807621 4. 5.83012702]
[3. 5.96410162 2.33012702]