具有非最小旋转弧的四元数生成

quaternion generation with non minimal rotation arc

numpy的四元数模块可以从sperical坐标生成四元数。示例:

theta = np.pi  / 3.0
phi = np.pi / 3.0
qRot = q.from_spherical_coords(theta,phi)

qRot quaternion(0.75, -0.25, 0.433012701892219, 0.433012701892219)

这个四元数将 Z 轴旋转到指向 theta、phi 坐标的单位向量 V。该四元数不产生最小旋转弧。最小旋转弧轴位于xy平面内。由于将 Z 移动到 V 的非最小旋转是无限的,因此产生四元数 qRot 的基本标准是什么?

感谢您的回复。

我假设您使用的是 numpy-quaternion 包。

In [2]: theta = np.pi  / 3.0
   ...: phi = np.pi / 3.0
   ...: 

(theta, phi) 四元数可以由 2 个四元数组成,一个是围绕 y 轴的旋转(你之前的问题),另一个是关于 z 轴的旋转:

In [3]: q1 = q.from_spherical_coords(theta,0)
In [4]: q1
Out[4]: quaternion(0.866025403784439, -0, 0.5, 0)
In [5]: q2 = q.from_spherical_coords(0,phi)
In [6]: q2
Out[6]: quaternion(0.866025403784439, -0, 0, 0.5)
In [7]: q12 = q.from_spherical_coords(theta,phi)
In [8]: q12
Out[8]: quaternion(0.75, -0.25, 0.433012701892219, 0.433012701892219)

In [9]: q1*q2
Out[9]: quaternion(0.75, 0.25, 0.433012701892219, 0.433012701892219)

也可以由一系列更小的旋转组成

In [11]: qn = q12**.1
In [12]: qn
Out[12]: quaternion(0.997389412687609, -0.0272930118179609, 0.0472728831602861, 0.0472728831602861)
In [13]: qn*qn
Out[13]: quaternion(0.989571281082665, -0.0544435220551839, 0.0942989463425753, 0.0942989463425753)
In [14]: qn**10
Out[14]: quaternion(0.75, -0.25, 0.433012701892219, 0.433012701892219)

我猜你所说的 minimal rotation arc 可以用这样一个小四元数序列产生的旋转来近似。

我不明白你为什么要声明这个弧的 'axis lies in the xy plane'。

并旋转单位Z轴:

In [17]: v=np.array([0,0,1])
In [23]: q.as_rotation_matrix(q1).dot(v)
Out[23]: array([0.8660254, 0.       , 0.5      ])

In [24]: q.as_rotation_matrix(q2).dot(_)
Out[24]: array([0.4330127, 0.75     , 0.5      ])

In [25]: q.as_rotation_matrix(q12).dot(v)
Out[25]: array([0.4330127, 0.75     , 0.5      ])

或作为一系列 qn 旋转:

In [26]: q.as_rotation_matrix(qn).dot(v)
Out[26]: array([0.09171851, 0.05891297, 0.99404073])
In [27]: q.as_rotation_matrix(qn**2).dot(v)
Out[27]: array([0.17636312, 0.12553607, 0.97628722])
In [28]: q.as_rotation_matrix(qn**3).dot(v)
Out[28]: array([0.25216838, 0.19847972, 0.94710977])
In [29]: q.as_rotation_matrix(qn**10).dot(v)
Out[29]: array([0.4330127, 0.75     , 0.5      ])

我仍在尝试找出使用此 class 进行计算和旋转的最佳方法。我会定期获取核心转储,因此它可能不是 numpy.

最强大的四元数包

https://math.stackexchange.com/q/7187


我的 qn 函数产生与 slerp 函数相同的四元数:q.slerp_evaluate(q1,q3,x)

https://en.wikipedia.org/wiki/Slerp#Quaternion_Slerp,

spherical linear interpolation, introduced by Ken Shoemake in the context of quaternion interpolation for the purpose of animating 3D rotation. It refers to constant-speed motion along a unit-radius great circle arc, given the ends and an interpolation parameter between 0 and 1.

我是通过借鉴早期关于几何代数旋转的阅读而偶然发现的,。它指的是沿单位半径大圆弧的恒速运动,给定端点和介于0和1之间的插值参数。

四元数

我厌倦了分段错误,并已切换到 pyquaternion。文档也更好。

http://kieranwynn.github.io/pyquaternion/

定义具有相同 (w,x,y,z) 值的四元数:

In [10]: q=Quaternion(np.array([0.75, -0.25, 0.433012701892219, 0.433012701892219]))
In [13]: q.rotation_matrix
Out[13]: 
array([[ 0.25     , -0.8660254,  0.4330127],
       [ 0.4330127,  0.5      ,  0.75     ],
       [-0.8660254, -0.       ,  0.5      ]])

旋转轴为:

In [16]: q.axis
Out[16]: array([-0.37796447,  0.65465367,  0.65465367])

这个四元数将 a 单位垂直旋转到:

In [17]: z=np.array([0,0,1])
In [18]: q.rotate(z)
Out[18]: array([0.4330127, 0.75     , 0.5      ])   # cf Out[25]

q1(In[3])(上一题)是:

In [28]: a1 = np.array([0.866025403784439, -0, 0.5, 0])
In [29]: q1 = Quaternion(a1)
In [30]: q1.axis
Out[30]: array([0., 1., 0.])
In [31]: q1.degrees
Out[31]: 59.999999999999986

即绕y轴旋转60度。

旋转弧的计算方式为:

In [32]: qn = q**.1
In [38]: np.array([(qn**n).rotate(z) for n in range(0,11)])
Out[38]: 
array([[0.        , 0.        , 1.        ],
       [0.09171851, 0.05891297, 0.99404073],
       [0.17636312, 0.12553607, 0.97628722],
       [0.25216838, 0.19847972, 0.94710977],
       [0.31755317, 0.27622248, 0.90711693],
       [0.37115374, 0.35714286, 0.85714286],
       [0.41185212, 0.43955305, 0.79822988],
       [0.43879944, 0.52173419, 0.73160678],
       [0.45143365, 0.6019722 , 0.65866314],
       [0.44949123, 0.67859351, 0.58092037],
       [0.4330127 , 0.75      , 0.5       ]])

描绘这条弧线有点棘手。该平面垂直于 q.axis,但不通过 (0,0,0) 原点。