小编Mar*_*ark的帖子

计算旋转矩阵以对齐 3D 空间中的两个向量?

我有两个独立的 3D 数据点向量,它们表示曲线,我正在使用 matplotlib 在 3D 图中将它们绘制为散点数据。

两个向量都从原点开始,并且都是单位长度。曲线彼此相似,但是,两条曲线之间通常存在旋转(出于测试目的,我实际上使用了一条曲线并对其应用了旋转矩阵以创建第二条曲线)。

我想对齐两条曲线,使它们在 3D 中对齐,例如旋转曲线 b,使其起点和终点与曲线 a 对齐。我一直试图通过从第一个点中减去最后一个点来做到这一点,以获得表示从每条曲线的起点到终点的直线的方向向量,将它们转换为单位向量,然后计算交叉和点积和使用本答案(https://math.stackexchange.com/a/476311/357495)中概述的方法来计算旋转矩阵。

但是,当我这样做时,计算出的旋转矩阵是错误的,我不知道为什么?

我的代码如下(我使用的是 Python 2.7):

# curve_1, curve_2 are arrays of 3D points, of the same length (both start at the origin) 

curve_vec_1 = (curve_1[0] - curve_1[-1]).reshape(3,1)
curve_vec_2 = (curve_2[index][0] - curve_2[index][-1]).reshape(3,1)
a,b = (curve_vec_1/ np.linalg.norm(curve_vec_1)).reshape(3), (curve_vec_2/ np.linalg.norm(curve_vec_2)).reshape(3)
v = np.cross(a,b)
c = np.dot(a,b)
s = np.linalg.norm(v)
I = np.identity(3)
vXStr = '{} {} {}; {} {} {}; {} {} {}'.format(0, -v[2], v[1], v[2], 0, …
Run Code Online (Sandbox Code Playgroud)

python 3d numpy python-2.7 rotational-matrices

5
推荐指数
4
解决办法
1万
查看次数

如何检查矩阵中的每一行是否等于数组并返回包含结果的布尔数组?

如何检查矩阵中的每一行是否等于数组并使用NumPy返回包含结果的布尔数组?例如

a = np.array([[1,2,3],[4,5,6],[7,8,9]])
b = np.array([4,5,6])

# Expected Result: [False,True,False]
Run Code Online (Sandbox Code Playgroud)

python arrays numpy matrix

0
推荐指数
1
解决办法
816
查看次数

标签 统计

numpy ×2

python ×2

3d ×1

arrays ×1

matrix ×1

python-2.7 ×1

rotational-matrices ×1