【发布时间】:2021-04-09 07:52:37
【问题描述】:
我试图找到旋转矩阵来对齐两个向量。
我有一个向量 A = [ax, ay, az],我想将它与向量 B = [1, 0, 0](x 轴单位向量)对齐。
def align_vectors(a, b):
v = np.cross(a, b)
s = np.linalg.norm(v)
c = np.dot(a, b)
v1, v2, v3 = v
h = 1 / (1 + c)
Vmat = np.array([[0, -v3, v2],
[v3, 0, -v1],
[-v2, v1, 0]])
R = np.eye(3, dtype=np.float64) + Vmat + (Vmat.dot(Vmat) * h)
return R
当我应用它来查找点的旋转时,这就是我所拥有的:
x_axis = np.array([1, 0, 0], dtype=np.float64)
direction = np.array([-0.02, 1.004, -0.02], dtype=np.float64)
Ralign = align_vectors(x_axis, direction)
point = 1000 * np.array([-0.02, 1.004, -0.02], dtype=np.float64) # Point in the direction of the unit vector
result = Ralign.dot(point)
结果点未与单位向量对齐。
【问题讨论】:
-
数学交换中的答案假设
a和b是单位向量。您需要重做数学以将长度包括在计算中。或先将它们标准化。