## 3. Transformations I: Linear Transformations (vector, matrix)

3. Transformations I: Linear Transformations. Multiple Transformations (2/14) … vectors & linear transformations (4×4 matrices)

Vector is length & direction, can be represented as 2D (dx, dy) or 3D (dx, dy, dz). Add vectors adds components (visually attach tail to head). Subtract vector just add the negative (visually flip direction of minus vector). To compute the length, use pythagorean theorem. Unit vector is vector length 1, compute by dividing the vector by its length.

Dot product A dot B = AxBx + AyBy + AzBz = cos(theta) * ||A|| * ||B||. Theta is the angle between A and B. ||A|| is magnitude of A. For unit vectors, A dot B = cos(theta). Because for unit vectors, ||A|| is 1 and ||B|| is 1. Dot product can tell you which side of a surface something is on. Example take the dot product of the Normal vector (to a plane) and the View vector (to the camera); the sign (greater than or less than zero) tells you if the angle is less than or greater than 90 degrees… Using dot product (instead of a trig function such as cosine).

Cross product in 3D: A cross B gives a third vector perpendicular to A and B. Use right-hand rule (A pointer finger, B middle, AxB thumb) for right-handed coordinate system. A cross B = (AyBz – AzBy, AzBx – AxBz, AxBy - AyBx). Mnemonic: to memorize this (for fun?), I think of each component’s subscripts for A*B-A*B as going xyzxyz-(reverse of that) and you start at X for X but there’s no X in the X (same for Y & Z). Cross product gives normal to a plane (used for lighting calculations) (typically 3D models created by 3D modeling software will have pre-computed normals saved as parameters for each vertex).

Linear transformation between two vector spaces is a map such that: L(k*A) = k*L(A) for scalar k. L(A+B) = L(A) + L(B). Lines are preserved. We do linear transformations with matrices. For 3D graphics, we use 4×4 matrices. Today we will talk about the top three rows (not the bottom row). Identity matrix:

(1 0 0 0)(x) (x)

(0 1 0 0)(y) = (y)

(0 0 1 0)(z) (z)

(0 0 0 1)(1) (1)

Scaling (negative values causes reflection). Translation (not a linear transformation in 3D, but it is in 4D, so we use the 4th column, which is why we have a 4×4 instead of 3×3). Shearing (stretching, parallel lines stay parallel) by axis (eg, to shear along Z, X and Y values are altered by an amount proportional to the value of Z, without changing Z).

(Sx Exy Exz Tx)(x) (Sx*x + Tx + y*Exy + z*Exz)

(Eyx Sy Eyz Ty)(y) = (Sy*y + Ty + x*Eyx + z*Eyz)

(Ezx Ezy Sz Tz)(z) (Sz*z + Tz + x*Ezx + y*Ezy)

(0 0 0 1 )(1) (1)

Rotation about x-axis, using right-hand rule:

( 1 0 0 0 )(x) ()

( 0 cos(a) -sin(a) 0 )(y) = ()

( 0 sin(a) cos(a) 0 )(z) ()

( 0 0 0 1 )(1) ()

Rotation about y-axis:

( cos(b) 0 sin(b) 0 )(x) ()

( 0 1 0 0 )(y) = ()

(-sin(b) 0 cos(a) 0 )(z) ()

( 0 0 0 1 )(1) ()

Rotation about z-axis:

( cos(c) -sin(c) 0 0 )(x) ()

( sin(c) cos(c) 0 0 )(y) = ()

( 0 0 1 0 )(z) ()

( 0 0 0 1 )(1) ()

There are other rotations, such as the general case is rotation about an arbitrary line, which can be simplified assuming the arbitrary line is a unit vector.

A taxonomy of some linear transformations. Rigid Body (preserve distance): rotation, translation. Similarity (preserve angles): rigid body, uniform scaling / reflection. Affine (preserve parallel lines): similarity, shear. Projective (preserves lines => lines stay straight => it’s a linear transformation).

The order of your transformations matters. For example, if you do rotation then translation, it’s different than if you do translation then rotation.

mepem37 :: 2013/09/28 (Saturday, September 28, 2013) :: CG intro Harvard, class videos :: No Comments »