我有2个3D点,我想绕Y轴旋转:
- A=(x1,y1,z1)
- B=(x2,y2,z2)
而且,我还有另外两个3D点,它们将用作提取旋转Angular 约束的参考.
- C=(x‘1,y’1,z‘1)
- D=(x‘2,y’2,z‘2)
我想绕Y轴旋转点A和B,使得线段AB(z1—z2)的高度与线段CD(z'1—z'2)的高度相同.
(编辑:根据 comments ,下面的数字似乎不清楚.下图表示XZ平面上的3D点投影.其意图是示出点A和B的投影,点A和B将绕Y轴旋转,使得线段AB的高度(h = z1—z2)将等于线段CD的高度(h ′ = z ′ 1—z ′ 2)).
而且,线段AB将总是足够长,使得解总是存在.
为了做到这一点,我首先写下了沿着Y轴旋转点A和B并将它们设置为等于点C和D的方程.(我只对等式的最后一行感兴趣,以保留高度约束):
使用最后一行,我可以提取以下方程组:
然后,为了求解这个方程组并求出Angular θ,我从第一个方程中减go 第二个方程,得到以下结果:
在(z ′ 1—z ′ 2)= 0的情况下,可以容易地求解方程,并且可以如下计算Angular :
然而,我遇到了困难的情况下,(z'1—z'2)不为零.
I tried to solve for the case where (z'1-z'2) is non-zero by dividing the first equation by the second equation:
然后,通过将方程的两边乘以分母,我就能够分离出一边的Angular θ,并计算arctan2,得到θ,如下所示:
我理解,通过使用这个方法,我假设z'2为非零,以便有一个解.我也明白,我可以用方程组中的方程2除以方程1,我会得到分母,z '1,我会假设它也是非零的.
因此,我开发了一个Python函数,它使用上面的公式计算θ,并返回旋转矩阵,然后将其用于沿Y轴旋转A和B:
def get_rot_y(current_points, reference_points):
(x1, y1, z1) = current_points[:, 0]
(x2, y2, z2) = current_points[:, 1]
(xp1, yp1, zp1) = reference_points[:, 0]
(xp2, yp2, zp2) = reference_points[:, 1]
if ((zp1-zp2) == 0):
th = np.arctan2((z2-z1), (x2-x1))
else:
th = np.arctan2((-z1 + (zp1*z2 / zp2)), (-x1 + (zp1*x2 / zp2)))
rot_y = np.array([
[np.cos(th), 0, np.sin(th)],
[0, 1, 0],
[-np.sin(th), 0, np.cos(th)],
])
return rot_y
然后,我测试了高度(z'1—z'2)为非零的情况下的函数:
A = np.array([1450, 0.5, -1545])
B = np.array([6000, 0.7, -1650])
C = np.array([1500, 0, -1500])
D = np.array([5600, 0, -1600])
current_height = A[2] - B[2]
desired_height = C[2] - D[2]
current_points = np.array([A, B]).T
reference_points = np.array([C, D]).T
rot_y = get_rot_y(current_points=current_points, reference_points=reference_points)
transfomed_points = rot_y @ current_points
transformed_height = transfomed_points[2,0] - transfomed_points[2,1]
print(f"current_height= {current_height}")
print(f"desired_height= {desired_height}")
print(f"transformed_height= {transformed_height}")
但是,当我执行代码时,我会得到以下输出:
current_height= 105.0
desired_height= 100
transformed_height= 102.95657644356697
如上所述,变换后的点的高度不等于期望的高度.
我做错了什么?对于我的问题,有没有一个解析解可以应用于(z'1—z'2)非零的情况?