Chapter 4 Transforms
A transform is an operation that takes entities such as points, vectors, or colors and converts them in some way.
变换是取点、矢量或颜色等实体并以某种方式转换它们的操作。
A linear transform is one that preserves vector addition and scalar multiplication.
线性变换是保留向量加法和标量乘法的变换。
Scaling and rotation transforms, in fact all linear transforms for three-element vectors, can be represented using a 3 × 3 matrix.
缩放和旋转变换,实际上是三元素向量的所有线性变换,可以用一个3 × 3矩阵来表示。
To prove that this is linear, the two conditions (Equations 4.1 and 4.2) need to be fulfilled.
为了证明这是线性的,需要满足两个条件(等式4.1和4.2)。
affine transform:Combining linear transforms and translations can be done using an affine transform, typically stored as a 4 × 4 matrix.
仿射变换:组合线性变换和平移可以使用仿射变换来完成,通常存储为4 × 4矩阵。
affine matrix:All translation, rotation, scaling, reflection, and shearing matrices are affine. The main characteristic of an affine matrix is that it preserves the parallelism of lines, but not necessarily lengths and angles.
所有平移、旋转、缩放、反射和剪切矩阵都是仿射的。仿射矩阵的主要特点是它保留了直线的平行性,但不一定保留长度和角度。
This chapter will begin with the most essential, basic affine transforms. This section can be seen as a “reference manual” for simple transforms. More specialized matrices are then described, followed by a discussion and description of quaternions, a powerful transform tool. Then follows vertex blending and morphing, which are two simple but effective ways of expressing animations of meshes. Finally, projection matrices are described. Most of these transforms, their notations, functions, and properties are summarized in Table 4.1, where an orthogonal matrix is one whose inverse is the transpose.
本章将从最基本的仿射变换开始。这部分可以看作是简单转换的“参考手册”。然后描述更专业的矩阵,接着讨论和描述四元数,一个强大的变换工具。然后是顶点混合和变形,这是表达网格动画的两种简单而有效的方法。最后,描述了投影矩阵。表4.1总结了这些变换中的大多数、它们的符号、函数和属性,其中正交矩阵的逆矩阵是转置矩阵。
Knowing what the matrix does after such a function call is a start, but understanding the properties of the matrix itself will take you further.
知道矩阵在这样的函数调用之后会做什么是一个开始,但是了解矩阵本身的属性会让你走得更远。
4.1.1 Translation
A change from one location to another is represented by a translation matrix, T. This matrix translates an entity by a vector t = (tx, ty, tz).
4.1.2 Rotation
Like a translation matrix, it is a rigid-body transform, i.e., it preserves the distances between points transformed, and preserves handedness (i.e., it never causes left and right to swap sides).
像平移矩阵一样,它是刚体变换,即它保留变换点之间的距离,并保留惯用手(即它从不导致左右交换边)。
An orientation matrix is a rotation matrix associated with a camera view or object that defines its orientation in space, i.e., its directions for up and forward.
方向矩阵是与相机视图或对象相关联的旋转矩阵,其定义了其在空间中的方向,即其向上和向前的方向。
vector, v = (vx, vy), which we parameterize as v = (vx, vy) = (r cos θ, r sin θ). If we were to rotate that vector by φ radians (counterclockwise), then we would get u = (r cos(θ + φ), r sin(θ + φ)).
向量v = (vx,vy),我们将其参数化为v = (vx,vy) = (r cos θ,r sin θ)。如果我们将向量旋转φ弧度(逆时针),那么我们将得到u = (r cos(θ + φ),r sin(θ + φ))。
In three dimensions, commonly used rotation matrices are Rx(φ), Ry(φ), and Rz(φ), which rotate an entity φ radians around the x-, y-, and z-axes, respectively.
在三维空间中,常用的旋转矩阵是Rx(φ)、Ry(φ)和Rz(φ),它们分别围绕x轴、y轴和z轴旋转实体φ弧度。
For every 3×3 rotation matrix, R, that rotates φ radians around any axis, the trace (which is the sum of the diagonal elements in a matrix) is constant independent of the axis, and is computed as [997]: tr(R) = 1 + 2 cos φ.
对于绕任意轴旋转φ弧度的每3×3旋转矩阵R,迹线(矩阵中对角元素的和)是不依赖于轴的常数,计算公式为[997]: tr(R) = 1 + 2 cos φ。
All rotation matrices have a determinant of one and are orthogonal. This also holds for concatenations of any number of these transforms. There is another way to obtain the inverse:
, i.e., rotate in the opposite direction around the same axis.
所有旋转矩阵的行列式都是1,并且是正交的。这也适用于任何数量的转换的连接。还有一种方法可以得到逆:
,即绕同一轴反方向旋转。
4.1.3 Scaling
A scaling matrix, S(s) = S(sx, sy, sz), scales an entity with factors sx, sy, and sz along the x-, y-, and z-directions, respectively.
缩放矩阵S(s) = S(sx,sy,sz)分别沿x、y和z方向用因子sx、sy和sz缩放实体。
Setting any of the components of s to 1 naturally avoids a change in scaling in that direction.
The scaling operation is called uniform if sx = sy = sz and nonuniform otherwise. Sometimes the terms isotropic and anisotropic scaling are used instead of uniform and nonuniform. The inverse is
A negative value on one or three of the components of s gives a type of reflection matrix, also called a mirror matrix.
s的一个或三个分量的负值给出了一种反射矩阵,也称为镜像矩阵。
If only two scale factors are −1, then we will rotate π radians. It should be noted that a rotation matrix concatenated with a reflection matrix is also a reflection matrix.
如果只有两个比例因子为-1,那么我们将旋转π弧度。应当注意,与反射矩阵连接的旋转矩阵也是反射矩阵。
4.1.4 Shearing
剪切
These can, for example, be used in games to distort an entire scene to create a psychedelic effect or otherwise warp a model’s appearance.
例如,这些可以在游戏中用来扭曲整个场景以产生迷幻效果,或者扭曲模型的外观。
There are six basic shearing matrices, and they are denoted Hxy(s), Hxz(s), Hyx(s), Hyz(s), Hzx(s), and Hzy(s). The first subscript is used to denote which coordinate is being changed by the shear matrix,while the second subscript indicates the coordinate which does the shearing.
有六个基本的剪切矩阵,它们被表示为Hxy、Hxz、Hyx、Hyz、Hzx和Hzy。第一个下标用来表示剪切矩阵正在改变哪个坐标,而第二个下标表示进行剪切的坐标。
Observe that the subscript can be used to find the position of the parameter s in the matrix below; the x (whose numeric index is 0) identifies row zero, and the z (whose numeric index is 2) identifies column two, and so the s is located there:
观察下标可以用来求参数s在下面矩阵中的位置;x(其数值索引为0)标识第0行,z(其数值索引为2)标识第2列,因此s位于此处:
The inverse of Hij(s) (shearing the ith coordinate with respect to the jth coordinate, where i 不等于 j), is generated by shearing in the opposite direction
Hij(s)的倒数(相对于jth坐标剪切ith坐标,其中i 不等于 j)是通过沿相反方向剪切产生的
You can also use a slightly different kind of shear matrix:
您也可以使用稍微不同的剪切矩阵:
Here, however, both subscripts are used to denote that these coordinates are to be sheared by the third coordinate. The connection between these two different kinds of descriptions is H′ij(s, t) = Hik(s)Hjk(t), where k is used as an index to the third coordinate. The right matrix to use is a matter of taste. Finally, it should be noted that since the determinant of any shear matrix |H| = 1, this is a volume-preserving transformation
然而,这里两个下标都用来表示这些坐标将被第三个坐标剪切。这两种不同类型的描述之间的联系是H ' ij(s,t) = Hik(s)Hjk(t),其中k用作第三个坐标的索引。正确的矩阵使用是一个品味的问题。最后,需要注意的是,由于任意剪切矩阵的行列式|H| = 1,这是一个保体积变换
4.1.5 Concatenation of Transforms
65