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)   ()

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

(   0      1       0      0   )(y) = ()
(-sin(b)   0     cos(a)   0   )(z)   ()
(   0      0       0      1   )(1)   ()