Real-Time Rendering——4.3.2 Quaternion Transforms四元数变换

We will now study a subclass of the quaternion set, namely those of unit length, called unit quaternions.

我们现在将研究四元数集的一个子类,即单位长度的四元数,称为单位四元数。


Given two unit quaternions, ˆq and ˆr, the concatenation of first applying ˆq and then ˆr to a quaternion, ˆp (which can be interpreted as a point p)

给定两个单位四元数,q和r,首先将q和r应用到四元数,p(可以解释为点p)的连接

Matrix Conversion 矩阵转换

A quaternion,q, can be converted into a matrix Mq

四元数q可以转换成矩阵Mq

The reverse conversion, from an orthogonal matrix, Mq, into a unit quaternion,ˆq, is a bit more involved. Key to this process are the following differences made from the matrix in Equation 4.46:

从正交矩阵Mq到单位四元数q的反向转换稍微复杂一些。这一过程的关键是方程4.46中矩阵的下列差异:

The implication of these equations is that if qw is known, the values of the vector vq can be computed, and thus ˆq derived. The trace of Mq is calculated by 

这些方程意味着,如果已知qw,就可以计算出矢量vq的值,从而推导出q。Mq的轨迹计算如下

This result yields the following conversion for a unit quaternion 

对于单位四元数,此结果产生以下转换

To have a numerically stable routine, divisions by small numbers should be avoided. 

为了有一个数值稳定的程序,应该避免用小数除。

which in turn implies that the largest of m00, m11, m22, and u determine which of qx, qy, qz, and qw is largest. If qw is largest, then Equation 4.49 is used to derive the quaternion. Otherwise, we note that the following holds: 

这又意味着m00、m11、m22和u中的最大值决定了qx、qy、qz和qw中的哪一个最大。如果qw最大,那么方程4.49用于导出四元数。否则,我们注意到以下情况成立:

The appropriate equation of the ones above is then used to compute the largest of qx,qy, and qz, after which Equation 4.47 is used to calculate the remaining components of ˆq. 

然后,使用上述等式中的适当等式来计算qx、qy和qz中的最大值,之后使用等式4.47来计算q的其余分量。

Spherical Linear Interpolation 球形线性插值

Spherical linear interpolation is an operation that, given two unit quaternions, ˆq and ˆr, and a parameter t ∈ [0, 1], computes an interpolated quaternion.

球面线性插值是给定两个单位四元数(q和r)和一个参数t ∈ [0,1],计算插值四元数的运算。

The algebraic form of this operation is expressed by the composite quaternion, ˆs,below:

该运算的代数形式由复合四元数s表示,如下所示:

However, for software implementations, the following form, where slerp stands for spherical linear interpolation, is much more appropriate: 

然而,对于软件实现,以下形式更合适,其中slerp代表球面线性插值:

The slerp function is perfectly suited for interpolating between two orientations and it behaves well (fixed axis, constant speed). This is not the case with when interpolating using several Euler angles.

slerp函数非常适合在两个方向之间进行插值 而且表现不错(定轴,恒速)。使用几个欧拉角进行插值时,情况并非如此。

A better way to interpolate is to use some sort of spline. We introduce quaternions ˆai and ˆai+1 between ˆqi and ˆqi+1. Spherical cubic interpolation can be defined within the set of quaternions ˆqi, ˆai, ˆai+1, and ˆqi+1. Surprisingly, these extra quaternions are computed as shown below 3:

更好的插值方法是使用某种样条。我们在ˇqi和ˇqi+1之间引入四元数ˇai和ˇai+1。球面三次插值可以在一组四元数qi、ai、ai+1和qi+1中定义。令人惊讶的是,这些额外的四元数的计算如下所示:

The ˆqi, and ˆai will be used to spherically interpolate the quaternions using a smooth cubic spline, as shown in Equation 4.55: 

ˇqi和ˇai将用于使用平滑三次样条对四元数进行球面插值,如等式4.55所示:

The interpolation will pass through the initial orientations ˆqi,i ∈ [0, . . . , n − 1], but not through ˆai—these are used to indicate the tangent orientations at the initial orientations. 

插值将通过初始方向qi,i ∈ [0,.。。,n1],但不通过a1-这些用于指示初始方向的切线方向。

Rotation from One Vector to Another

从一个向量到另一个向量的旋转

A common operation is transforming from one direction s to another direction t via the shortest path possible. The mathematics of quaternions simplifies this procedure greatly, and shows the close relationship the quaternion has with this representation.

常见的操作是通过可能的最短路径从一个方向s转换到另一个方向t。四元数的数学极大地简化了这一过程,并显示了四元数与这一表示的密切关系。

First, normalize s and t. Then compute the unit rotation axis, called u, which is computed as u = (s × t)/||s × t||. Next, e = s · t = cos(2φ) and ||s × t|| = sin(2φ),where 2φ is the angle between s and t. The quaternion that represents the rotation from s to t is then ˆq = (sin φu, cos φ).

首先归一化s和t,然后计算单位旋转轴,称为u,计算方法为u = (s × t)/||s × t||。接下来,e = s t = cos(2φ)和||s × t|| = sin(2φ),其中2φ是s和t之间的角度,那么表示从s到t的旋转的四元数就是ˇq =(sinφu,cos φ)。

 using the half-angle relations and the trigonometric identity, gives

利用半角关系和三角恒等式,给出

Directly generating the quaternion in this fashion (versus normalizing the cross product s × t) avoids numerical instability when s and t point in nearly the same direction. 

以这种方式直接生成四元数(相对于归一化叉积s × t)避免了s和t几乎指向同一方向时的数值不稳定性。

Stability problems appear for both methods when s and t point in opposite directions, as a division by zero occurs. When this special case is detected,any axis of rotation perpendicular to s can be used to rotate to t.

当s和t指向相反的方向时,两种方法都会出现稳定性问题,因为会被零除。当检测到这种特殊情况时,任何垂直于s的旋转轴都可以用来旋转到t。

Sometimes we need the matrix representation of a rotation from s to t. After some algebraic and trigonometric simplification of Equation 4.46, the rotation matrix becomes

有时我们需要从s到t的旋转的矩阵表示。在对方程4.46进行一些代数和三角简化后,旋转矩阵变成

In this equation, we have used the following intermediate calculations: 

在这个等式中,我们使用了以下中间计算:

Note that care must be taken when s and t are parallel or near parallel, because then ||s × t|| ≈ 0. If φ ≈ 0, then we can return the identity matrix. However, if 2φ ≈ π, then we can rotate π radians around any axis. This axis can be found as the cross product between s and any other vector that is not parallel to s (Section 4.2.4).M¨oller and Hughes use Householder matrices to handle this special case in a differentway. 

注意,当s和t平行或接近平行时必须小心,因为这时||s × t|| ≈ 0。如果φ ≈ 0,那么我们可以返回单位矩阵。但是,如果2φ ≈ π,那么我们可以绕任意轴旋转π弧度。这个轴可以作为s和任何其他不平行于s的矢量的叉积找到(4.2.4节)。穆勒和休斯使用霍尔德矩阵以不同的方式处理这种特殊情况。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

椰子糖莫莫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值