Chapter 4 Transforms
A transform is an operation that takes entities such as points, vectors, or colors and converts them in some way.
變換是取點(diǎn)逼纸、矢量或顏色等實(shí)體并以某種方式轉(zhuǎn)換它們的操作遏弱。
A linear transform is one that preserves vector addition and scalar multiplication.
線性變換是保留向量加法和標(biāo)量乘法的變換授舟。
Scaling and rotation transforms, in fact all linear transforms for three-element vectors, can be represented using a 3 × 3 matrix.
縮放和旋轉(zhuǎn)變換,實(shí)際上是三元素向量的所有線性變換缀匕,可以用一個(gè)3 × 3矩陣來表示纳决。
To prove that this is linear, the two conditions (Equations 4.1 and 4.2) need to be fulfilled.
為了證明這是線性的,需要滿足兩個(gè)條件(等式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.
仿射變換:組合線性變換和平移可以使用仿射變換來完成岳链,通常存儲(chǔ)為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.
所有平移劲件、旋轉(zhuǎn)、縮放约急、反射和剪切矩陣都是仿射的零远。仿射矩陣的主要特點(diǎn)是它保留了直線的平行性,但不一定保留長(zhǎng)度和角度厌蔽。
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.
本章將從最基本的仿射變換開始牵辣。這部分可以看作是簡(jiǎn)單轉(zhuǎn)換的“參考手冊(cè)”。然后描述更專業(yè)的矩陣奴饮,接著討論和描述四元數(shù)纬向,一個(gè)強(qiáng)大的變換工具择浊。然后是頂點(diǎn)混合和變形,這是表達(dá)網(wǎng)格動(dòng)畫的兩種簡(jiǎn)單而有效的方法逾条。最后琢岩,描述了投影矩陣。表4.1總結(jié)了這些變換中的大多數(shù)师脂、它們的符號(hào)担孔、函數(shù)和屬性,其中正交矩陣的逆矩陣是轉(zhuǎn)置矩陣吃警。
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.
知道矩陣在這樣的函數(shù)調(diào)用之后會(huì)做什么是一個(gè)開始糕篇,但是了解矩陣本身的屬性會(huì)讓你走得更遠(yuǎn)。
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).
像平移矩陣一樣酌心,它是剛體變換拌消,即它保留變換點(diǎn)之間的距離,并保留慣用手(即它從不導(dǎo)致左右交換邊)谒府。
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.
方向矩陣是與相機(jī)視圖或?qū)ο笙嚓P(guān)聯(lián)的旋轉(zhuǎn)矩陣拼坎,其定義了其在空間中的方向,即其向上和向前的方向完疫。
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),我們將其參數(shù)化為v = (vx壳鹤,vy) = (r cos θ盛龄,r sin θ)。如果我們將向量旋轉(zhuǎn)φ弧度(逆時(shí)針)芳誓,那么我們將得到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.
在三維空間中锹淌,常用的旋轉(zhuǎn)矩陣是Rx(φ)匿值、Ry(φ)和Rz(φ),它們分別圍繞x軸赂摆、y軸和z軸旋轉(zhuǎn)實(shí)體φ弧度挟憔。
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 φ.
對(duì)于繞任意軸旋轉(zhuǎn)φ弧度的每3×3旋轉(zhuǎn)矩陣R,跡線(矩陣中對(duì)角元素的和)是不依賴于軸的常數(shù)烟号,計(jì)算公式為[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.
所有旋轉(zhuǎn)矩陣的行列式都是1,并且是正交的汪拥。這也適用于任何數(shù)量的轉(zhuǎn)換的連接达传。還有一種方法可以得到逆:
,即繞同一軸反方向旋轉(zhuǎn)。
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縮放實(shí)體罕伯。
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的一個(gè)或三個(gè)分量的負(fù)值給出了一種反射矩陣岛蚤,也稱為鏡像矩陣邑狸。
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.
如果只有兩個(gè)比例因子為-1,那么我們將旋轉(zhuǎn)π弧度涤妒。應(yīng)當(dāng)注意单雾,與反射矩陣連接的旋轉(zhuǎn)矩陣也是反射矩陣。
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.
例如她紫,這些可以在游戲中用來扭曲整個(gè)場(chǎng)景以產(chǎn)生迷幻效果硅堆,或者扭曲模型的外觀。
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.
有六個(gè)基本的剪切矩陣贿讹,它們被表示為Hxy渐逃、Hxz、Hyx民褂、Hyz茄菊、Hzx和Hzy。第一個(gè)下標(biāo)用來表示剪切矩陣正在改變哪個(gè)坐標(biāo)赊堪,而第二個(gè)下標(biāo)表示進(jìn)行剪切的坐標(biāo)面殖。
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:
觀察下標(biāo)可以用來求參數(shù)s在下面矩陣中的位置;x(其數(shù)值索引為0)標(biāo)識(shí)第0行哭廉,z(其數(shù)值索引為2)標(biāo)識(shí)第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)的倒數(shù)(相對(duì)于jth坐標(biāo)剪切ith坐標(biāo),其中i 不等于 j)是通過沿相反方向剪切產(chǎn)生的
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
然而遵绰,這里兩個(gè)下標(biāo)都用來表示這些坐標(biāo)將被第三個(gè)坐標(biāo)剪切辽幌。這兩種不同類型的描述之間的聯(lián)系是H ' ij(s,t) = Hik(s)Hjk(t)街立,其中k用作第三個(gè)坐標(biāo)的索引舶衬。正確的矩陣使用是一個(gè)品味的問題埠通。最后赎离,需要注意的是,由于任意剪切矩陣的行列式|H| = 1端辱,這是一個(gè)保體積變換
4.1.5 Concatenation of Transforms
65