230 likes | 294 Views
SE 313 – Computer Graphics. Lecture 7 : Mathematical Basis for 3D Transformations Lecturer: Gazihan Alankuş. Please look at the last three slides for assignments (marked with TODO ). Plan for Today. One hour lecture Two hour quiz and lab. Exam Talk. Next week is the midterm exam
E N D
SE 313 – Computer Graphics Lecture 7: Mathematical Basis for 3D Transformations Lecturer: GazihanAlankuş Please look at the last three slides for assignments (marked with TODO)
Plan for Today • One hour lecture • Two hour quiz and lab
Exam Talk • Next week is the midterm exam • I can ask about anything that we have done here. • Slides may not be enough.
Our Goal • Understand the mathematical basis of 3D transformations.
What we know already • Math • Point, vector, magnitude, dot product, cross product, etc. • Transformations • Translation, rotation, scale • They have a mathematical basis
What will we transform? • Objects are made of points • Pairs of such points define vectors • Points • Translate, rotate? (around origin), scale? (wrt. origin) • Vectors • Translate?(no!), rotate, scale
Translation • How can we move an object? • Add numbers to the coordinates of all of its points • Explanation on the board
Rotation • How can we rotate an object (around the origin)? • Trigonometry! • Ok but how can we make these calculations more systematically? • Matrix-vector multiplication! • M x v (the column vector is on the right) • Explanation on the board
Scale • How can we scale an object (wrt the origin)? • Multiplication! • Explanation on the board
Combining Transformations • Of the same kind • Translation • Just add the numbers that you will add for each • Scale • Just multiply the numbers that you will multiply for each • Rotate? • Guess what, matrix multiplication from linear algebra is actually useful
Combining Transformations • What if I want to do “rotate, translate, and then rotate” like we did last week? • How will you combine element-wise addition, element-wise multiplication and matrix multiplication? • You can’t. Unless you make them be the same operation.
Scaling as Matrix Multiplication • Instead of doing element-wise multiplication, why not get an identity matrix, multiply the diagonals of that identity matrix with the scale factors and then use it? • Explanation on the board
Scaling as Matrix Multiplication • Now we can combine rotation and scale however we wish! • R x S x R x R x S x S x R x S • The result is still a 3 by 3 matrix! Ready to be applied to a vector or combined with whatever else you’ve got!
Translation as a matrix multiplication? • Think about it for a minute.
Translation as a matrix multiplication? • It is possible if we add one more dimension • The fourth column holds the translation nicely – very clever hack • Explanation on the board
Homogeneous Coordinates • Four entities in a column vector represent three dimensions. The last entry is always 1. If not, divide all with the last entry. • The fourth dimension does not have any significant meaning. It’s just a hack. • 3x3 rotation/scale matrices -> 4x4 matrices with the rest coming from identity • Transformation column vectors -> 4x4 identity matrices, with the column vector pasted to the fourth column.
Combining Transformations Using Homogeneous Coordinates • Mr x Mt x Ms x Mt x Mr x Mr x Mt • Still a 4x4 matrix, ready to be applied to your 3 dimensional column vectors with a 1 in the end (for points) • For vectors, you put a 0 in the end. Remember slide #4, you cannot translate vectors! • The math works nicely.
Combining Transformations and the Order of Matrix Multiplication • When you read the matrix multiplication from left to right, it is the world-to-local order of applying transformations
Combinations of Translations and Rotations • Mt x Mr x Mr x Mt x Mt x Mr • Whichever order you apply, this is equal to Mt’ x Mr’ for some t’ and r’ • The 3x3 part of the matrix is the rotation • The last column is the translation
More interesting facts • When you apply a transformation to an object that was straight in the origin, the object’s local coordinate frame moves with the object. The location and the x, y, z vectors of this local frame can be represented in global coordinates. • The x, y, z vectors of the local coordinate frame are the first three columns of the transformation matrix! • The location of this local coordinate frame is the fourth column of the transformation matrix. • You can use this information to construct transformation matrices.
Quaternions • 3x3 matrices have too much data. We can represent it with three numbers (three rotations). But this does not play well with mathematics. • Instead, we represent them with four numbers. Quaternions happen to be a good mathematical construct for this. • , blah blahblah. DON’T CARE! We don’t need them.
Quaternions • What we care about is that they represent rotations as an angle and an axis • http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation • They encode it in a funny way though: • Or, the four tuple: • We still do not care as strongly. Just know that, for you, quaternion means rotation. • You can use it instead of 3x3 matrices • You can create it using an axis and an angle • You can extract from it an axis and an angle • With quaternion multiplication, you can combine them just like you combine matrices • Most 3D libraries enable you to rotate a vector with a quaternion
Quizzes and Lab • For two hours, the assistant will administer • A closed-book quiz (15 minutes, on paper) • An open-book quiz (rest of class, on paper) • The blender implementation of the last two questions of the open-book quiz (graded by demonstrating to the assistant)