CMSC427 Computer Graphics
Matthias Zwicker Fall 2018 Today Transformations & matrices • Introduction • Affine transformations • Concatenating transformations
2 Introduction • Goal: Freely position rigid objects in 3D space
3 Today Transformations & matrices • Introduction • Affine transformations • Concatenating transformations
4 Affine transformations • Transformation, or mapping: function that maps each 3D point to a new 3D point „f: R3 -> R3“ • Affine transformations: class of transformations to position 3D objects in space • Affine transformations include – Rigid transformations • Rotation • Translation – Non-rigid transformations • Scaling • Shearing
5 Affine transformations • Definition: mappings that preserve colinearity and ratios of distances http://en.wikipedia.org/wiki/Affine_transformation – Straight lines are preserved – Parallel lines are preseverd • Linear transformations + translation • Nice: All desired transformations (translation, rotation) implemented using homogeneous coordinates and matrix- vector multiplication
6 Problem statement • If you know the (rigid, or affine) transformation that you want to apply, how do you construct a matrix that implements that transformation? – For example, given translation vector, rotation angles, what is the matrix that implements this?
7 Translation Point Vector
8 Matrix formulation Point Vector
9 Matrix formulation • Inverse translation
• Verify that
10 Poll
Given vector t and a corresponding translation matrix T(t), you want to translate by 2*t. The corresponding translation matrix is:
A. T(t)+T(t) B. T(t)*T(t) C. None of the above
11 Note • What happens when you translate a vector?
12 Rotation First: rotating a vector in 2D • Convention: positive angle rotates counterclockwise • Express using rotation matrix
13 Rotating a vector in 2D
14 Rotating a vector in 2D
15 Rotating a vector in 2D
16 Rotation in 3D Rotation around z-axis • z-coordinate does not change
0 v = R z(µ)v
• What is the matrix for ?
17 Other coordinate axes • Same matrix to rotate points and vectors • Points are rotated around origin
18 Poll
Which of these matrices is a rotation matrix?
A. Neither one B. A is, but B isn’t C. A isn’t, but B is D. Both
19 Rotation in 3D • Concatenate rotations around x,y,z axes to obtain rotation around arbitrary axes through origin
Gimbal • are called Euler angles https://en.wikipedia.org/wiki/Gimbal http://en.wikipedia.org/wiki/Euler_angles • Disadvantage: result depends on order!
20 Rotation around arbitrary axis • Still: origin does not change • Counterclockwise rotation • Angle , unit axis •
• Intuitive derivation see http://mathworld.wolfram.com/RotationFormula.html 21 Summary • Different ways to describe rotations mathematically – Sequence of rotations around three axes (Euler angles) – Rotation around arbitrary angles (axis-angle representation) – Other options exist (quaternions, etc.) • Rotations preserve – Angles – Lengths – Handedness of coordinate system • Rigid transforms – Rotations and translations
22 Rotation matrices • Orthonormal – Rows, columns are unit length and orthogonal • Inverse of rotation matrix?
23 Rotation matrices • Orthonormal – Rows, columns are unit length and orthogonal • Inverse of rotation matrix? – Its transpose
24 Rotations • Given a rotation matrix • How do we obtain ?
25 Rotations • Given a rotation matrix • How do we obtain ?
26 Rotations • Given a rotation matrix • How do we obtain ?
• How do we obtain …?
27 Rotations • Given a rotation matrix • How do we obtain ?
• How do we obtain …?
28 Scaling • Origin does not change
29 Scaling • Inverse scaling?
30 Scaling • Inverse scaling?
31 Shear
• Pure shear if only one parameter is non-zero • Cartoon-like effects
32 Summary affine transformations • Linear transformations (rotation, scale, shear, reflection) + translation
Vector space, Affine space http://en.wikipedia.org/wiki/Vector_space http://en.wikipedia.org/wiki/Affine_space • vectors as [xyz] • points and vectors coordinates as [xyz1], [xyz0] • represents vectors homogeneous • 3x3 matrix multiplication coordinates implements linear • distinguishes points transformations and vectors • 4x4 matrix mult. implements linear trafos. and translation
33 Summary affine transformations • Implemented using 4x4 matrices, homogeneous coordinates – Last row of 4x4 matrix is always [0 0 0 1] • Any such matrix represents an affine transformation in 3D • Factorization into scale, shear, rotation, etc. is always possible, but non-trivial – Polar decomposition http://en.wikipedia.org/wiki/Polar_decomposition
34 Today Transformations & matrices • Introduction • Affine transformations • Concatenating transformations
35 Concatenating transformations • Build “chains” of transformations
• Apply followed by followed by • Overall transformation is an affine transformation
36 Concatenating transformations • Result depends on order because matrix multiplication not commutative • Thought experiment – Translation followed by rotation vs. rotation followed by translation
37 Rotating with pivot
Rotation around Rotation with origin pivot
38 Rotating with pivot
1. Translation 2. Rotation 3. Translation
39 Rotating with pivot
1. Translation 2. Rotation 3. Translation
40 Concatenating transformations • Arbitrary sequence of transformations
• Note: associativity
T=M3.multiply(M2); Mtotal=T.multiply(M1) T=M2.multiply(M1); Mtotal=M3.multiply(T)
41 Coming up • From 3D to 2D: projections
42