len3d

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

在以前涉及的程序中,处理物体的旋转通常是用的矩阵的形式。由于硬件在纹理映射和光栅化上的加强,程序员可以将更多的CPU周期用于物理模拟等工作,这样将使得程序更为逼真。

一,原文出处: http://www.gamasutra.com/features/19980703/quaternions_01.htm

二,摘录:

有三种办法表示旋转:矩阵表示,欧拉角表示,以及四元组表示。矩阵,欧拉角表示法在处理插值的时候会遇到麻烦。
There are many ways to represent the orientation of an object. Most programmers use 3x3 rotation matrices or three Euler angles to store this information. Each of these solutions works fine until you try to smoothly interpolate between two orientations of an object.


矩阵表示法不适合于进行插值(在转动的前后两个朝向之间取得瞬时朝向)。矩阵有9个自由度(3×3矩阵),而实际上表示一个旋转只需要3个自由度(旋转轴3)。
Rotations involve only three degrees of freedom (DOF), around the x, y, and z coordinate axes. However, nine DOF (assuming 3x3 matrices) are required to constrain the rotation - clearly more than we need.

Another shortcoming of rotation matrices is that they are extremely hard to use for interpolating rotations between two orientations. The resulting interpolations are also visually very jerky, which simply is not acceptable in games any more.

欧拉角表示法
You can also use angles to represent rotations around three coordinate axes. You can write this as (q, c, f); simply stated, "Transform a point by rotating it counterclockwise about the z axis by q degrees, followed by a rotation about the y axis by c degrees, followed by a rotation about the x axis by f degrees."

欧拉角表示法的缺陷:把一个旋转变成了一系列的旋转。并且,进行插值计算也不方便。
However, there is no easy way to represent a single rotation with Euler angles that corresponds to a series of concatenated rotations. Furthermore, the smooth interpolation between two orientations involves numerical integration


目录

[隐藏]

四元组表示法

[w, v]其中v是矢量,表示旋转轴。w标量,表示旋转角度。所以,一个四元组即表示一个完整的旋转。
There are several notations that we can use to represent quaternions. The two most popular notations are complex number notation (Eq. 1) and 4D vector notation (Eq. 2).

w + xi + yj + zk (where i2 = j2 = k2 = -1 and ij = k = -ji with real w, x, y, z) (Eq. 1)

[w, v] (where v = (x, y, z) is called a "vector" and w is called a "scalar") (Eq. 2)

4D空间以及单元四元组:
Each quaternion can be plotted in 4D space (since each quaternion is comprised of four parts), and this space is called quaternion space. Unit quaternions have the property that their magnitude is one and they form a subspace, S3, of the quaternion space. This subspace can be represented as a 4D sphere. (those that have a one-unit normal), since this reduces the number of necessary operations that you have to perform.


四元组的基本运算法则

Table 1. Basic operations using quaternions.

Addition: q + q´ = [w + w´, v + v´]

Multiplication: qq´ = [ww´ - v · v´, v x v´ + wv´ +w´v] (· is vector dot product and x is vector cross product); Note: qq´ ? q´q
//为什么是这样?--定义成这样滴,木有道理可以讲
Conjugate: q* = [w, -v] 共轭

Norm: N(q) = w2 + x2 + y2 + z2 模

Inverse: q-1 = q* / N(q)

Unit Quaternion: q is a unit quaternion if N(q)= 1 and then q-1 = q*

Identity: [1, (0, 0, 0)] (when involving multiplication) and [0, (0, 0, 0)] (when involving addition)


用四元组进行旋转的公式

重要!!!!:只有单元四元组才表示旋转。为什么????--已解决(shoemake有详细证明)
It is extremely important to note that only unit quaternions represent rotations, and you can assume that when I talk about quaternions, I'm talking about unit quaternions unless otherwise specified.

Since you've just seen how other methods represent rotations, let's see how we can specify rotations using quaternions. It can be proven (and the proof isn't that hard) that the rotation of a vector v by a unit quaternion q can be represented as

v´ = q v q-1 (where v = [0, v]) (Eq. 3)


////////////////////////////////////////////////////////////

四元组和旋转参数的变换一个四元组由(x,y,z,w)四个变量表达,假设给定一个旋转轴axis和角度angle,那么这个四元组的计算公式为:


void Quaternion::fromAxisAngle(const Vector3 &axis, Real angle)
{
Vector3 u = axis;
u.normalize();
Real s = Math::rSin(angle/2.f);
x = s*u.x;
y = s*u.y;
z = s*u.z;
w = Math::rCos(angle/2.f);
}


由四元组反算回旋转轴axis和角度angle的公式为:

/
void Quaternion::toAxisAngle(Vector3 &axis, Real &angle) const
{
angle = acos(w)*2
axis.x = x
axis.y = y
axis.z = z
}

/////////////////////////////////////////////////////////////

《quatinians》 by shoemake :从纯数学的角度进行解释。

  • 内容
    • 更多的运算性质(数学符号太多,懒得对照了)。
    • 证明可以用单元四元组表示旋转。
    • 推倒出四元组和矩阵的相互转换。
posted on 2008-02-04 12:09  Len3d  阅读(1568)  评论(2编辑  收藏  举报