Title: CSE 681 Brief Review: Matrices, Vectors, and Transformations
1CSE 681Brief ReviewMatrices, Vectors, and
Transformations
2Overview
- Mathematical toolbox
- Review basic matrix and vector algebra
- Line representation
- Affine transformations
- Composing transformations
- Axial rotations Euler angles
- Rotation about an arbitrary axis
3What is a Matrix?
- A matrix is a set of elements, organized into
rows and columns
rows
columns
4Basic Operations
- Addition, Subtraction, Multiplication
Just add elements
Just subtract elements
Multiply each row by each column
5Multiplication
- Is AB BA? Maybe, but maybe not!
- Multiplication is NOT commutative!
6Inverse of a Matrix
- Identity matrix AI A
- Inverse MatrixAA-1 I
- Useful equivalence(ABC)-1 C-1B-1A-1
7Determinant of a 2 x 2 Matrix
- Useful for inversion
- If det(A) 0
- Then A has no inverse
- Easy for a 2 x 2 matrix
8Determinant of a 3 x 3 Matrix
Sum from left to right Subtract from right to
left Note n! terms
9Inverse of a 3 x 3 Matrix
- Append the identity matrix to A
- Apply Gaussian Elimination so that A turns into
the identity - Transform the identity matrix as you go
- The identity has become the inverse!
10Vector Operations
- Vector 1 x N matrix
- Looks like a point
- Vector has its tail at the origin head at the
point - Magnitude (length) and direction
y
v
x
11Vectors Dot Product
Think of the dot product as a matrix
multiplication
The magnitude is the dot product of a vector with
itself
The dot product is also related to the angle
between the two vectors
12Dot Product
- A . B B . A
- If A and B are unit vectors, A . B cos(q)
- Remember, A . B A B cos(q)
- If A is a unit vector, A . B is length of B
projected onto A
13Vectors Cross Product
- A x B C, where vector C is perpendicular to A
and B - The magnitude of C is proportional to the sine of
the angle between A and B - The direction of C depends on the handedness of
the coordinate system.
14Cross Product
- A x B -(B x A)
- A x B is orthogonal to plane defined by A and B
- If A and B are unit vectors, A x B sin(?)
15Line Equation
- We need a way to represent a ray, i.e. an
infinite line - How would you define a line mathematically?
16Line Equation
- Two points determine a line, say between
endpoints P0(x, y, z) and P1(x, y, z) - A line equation of the form f (x, y, z) is
cumbersome since it depends upon on all three
variables simultaneously - More convenient to define the line with a single
variable - Will become clearer when we implement our ray
tracer - How do we do this?
17Parametric Line Equation
- Define a single variable t that parameterizes the
line simultaneously for all dimensions x, y, and
z - P(t) P0(x, y, z) (1 t) P1(x, y, z) t
- where 0 t 1.0
t 1
t 0
P1
P0
18Parametric Line Equation
- Re-write P(t)
- P(t) P0(x, y, z) t D(x, y, z)
- where D(x, y, z) P1(x, y, z) P0(x, y, z)
- Furthermore,
- x(t) P0(x) t Dx
- y(t) P0(y) t Dy
- z(t) P0(z) t Dz
19ReviewTransformations
20Transformations - Modeling
21Modeling
How do I place the spheres ?
22 Viewing
Orthographic
Perspective
23Modeling Transformations
Transform coordinate system
24Affine Transformations
- A transformation that preserves
- Collinearity
- All points lying on a line initially still lie on
a line after the transformation - Parallel lines stay parallel
- Ratios of distances
- The midpoint of a line segment remains the
midpoint after transformation - Does not necessarily preserve lengths or angles
25Affine Transformations
- Lets talk about transforming points
- Transform P (x, y, z) to Q (x, y, z)
- General form of an Affine transformation
- x m11x m12 y m13z m14
- y m21 x m22 y m23z m24
- z m31 x m32 y m33z m34
26Translation
- Translation by (tx, ty, tz)
- x x tx
- y y ty
- z z tz
(tx, ty, tz)
27Scaling
- Scaling by (sx, sy, sz)
- x sx x
- y sy y
- z sz z
28Rotation
- Rotation counter-clockwise by angle ? around the
z-axis - x x cos(?) y sin(?)
- y x sin(?) y cos(?)
- z z
Derivation x r cos(?) y r sin(?) x r
cos(? ?) r cos(?) cos(?) r sin(?) sin(?)
x cos(?) y sin(?) y r sin(? ?) r cos(?)
sin(?) r sin(?) cos(?) x sin(?) y cos(?)
29Rotation Around the x-axis
- Rotation counter-clockwise by angle ? around the
x-axis - x x
- y y cos(?) z sin(?)
- z y sin(?) z cos(?)
z
?
y
x
30Rotation Around the y-axis
- Rotation counter-clockwise by angle ? around the
y-axis - y y
- z z cos(?) x sin(?)
- x z sin(?) x cos(?)
- Or
- x x cos(?) z sin(?)
- y y
- z x sin(?) z cos(?)
x
?
z
y
31Matrix Multiplication
- Scaling by (sx, sy, sz)
- x sx x
- y sy y
- z sz z
- Rotation counter-clockwise by angle ? around the
z-axis - x x cos(?) y sin(?)
- y x sin(?) y cos(?)
- z z
- Translation by (tx, ty, tz)
- x x tx
- y y ty
- z z tz
32Homogeneous Coordinates
- Represent P by (x, y, z, 1) and Q by (x, y, z,
1) - Translation by (tx, ty, tz)
- x x tx
- y y ty
- z z tz
- Scaling by (sx, sy, sz)
- x sx x
- y sy y
- z sz z
33Rotation Matrices
- Rotation counter-clockwise by angle ? around the
z-axis - x x cos(?) y sin(?)
- y x sin(?) y cos(?)
- z z
- Rotation counter-clockwise by angle ? around the
x-axis - x x
- y y cos(?) z sin(?)
- z y sin(?) z cos(?)
- Rotation counter-clockwise by angle ? around the
y-axis - x x cos(?) z sin(?)
- y y
- z x sin(?) z cos(?)
34Affine Transformation Matrix
- Affine transformation
- x m11 x m12 y m13 z m14
- y m21 x m22 y m23 z m24
- z m31 x m32 y m33 z m34
- Transformation Matrix
35Shearing
- Shear along the x-axis
- x x hy
- y y
- z z
36Reflection
- Reflection across the x-axis
- x x
- y (-1) y
- z z
Reflection is a special case of scaling!
37Compose Transformations
38Compose Transformation Matrices
- Rotate by 30 counter-clockwise around the
z-axis
- Translate by (0, -50, 0).
Translate
Rotate
Scale
39Compose Transformation Matrices
- Rotate by 30 counter-clockwise around the
z-axis
- Translate by (0, -50, 0).
40Order Matters!
- Transformations are not necessarily commutative!
- Translate by (20, 0, 0).
- Rotate by 30?.
- Rotate by 30?.
- Translate by (20, 0, 0).
41Order of Transformation Matrices
- Apply transformation matrices from right to left.
- Translate by (20, 0, 0).
- Rotate by 30?.
- Rotate by 30?.
- Translate by (20, 0, 0).
42Elementary Transformations
- Theorem Every affine transformation can be
decomposed into elementary operations - (For example a rotation, then a scaling and
finally a translation) - Elementary transformations
- Translation
- Rotation
- Scaling
- Shear
43Eulers Theorem
- Every rotation around the origin can be
decomposed into a rotation around the x-axis
followed by a rotation around the y-axis followed
by a rotation around the z-axis
44Fixed Point Transformations
- Sometimes it is convenient to transform to the
origin first, then perform your operations - Take the hatchet in this example
45Fixed Point Transforms
46Fixed Point Scaling
- Assuming that (xp, yp) is our fixed point (2D
example) - 1. Translate (xp, yp) to the origin
- 2. Scale by Sx and Sy
- 3. Translate the origin back to (xp, yp)
- Expressing (x, y) in terms of (x, y) we
get
47Rotation About An Arbitrary Axis
y
u
Q
Rotate P to Q by angle b about an arbitrary axis
(vector) u?
P
x
z
48Rotation About An Arbitrary Axis
- Make axis u coincident with axis x
- Two rotations Rz(-f) Ry(q)
- Apply transformation to P as well
- Rotate P around x-axis Rx(b)
- Undo earlier rotations Ry(-q) Rz(f)
- R Ry(-q) Rz(f) Rx(b) Rz(-f) Ry(q) Eulers
Theorem!
What OpenGL command can construct this matrix?
glRotate