se 313 – computer graphics

23
SE 313 – Computer Graphics Lecture 7: Mathematical Basis for 3D Transformations Lecturer: Gazihan Alankuş lease look at the last three slides for assignments (marked with TO 1

Upload: danil

Post on 06-Feb-2016

22 views

Category:

Documents


0 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: SE 313 – Computer Graphics

1

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)

Page 2: SE 313 – Computer Graphics

2

Plan for Today

• One hour lecture• Two hour quiz and lab

Page 3: SE 313 – Computer Graphics

3

Exam Talk

• Next week is the midterm exam• I can ask about anything that we have done

here. – Slides may not be enough.

Page 4: SE 313 – Computer Graphics

4

Our Goal

• Understand the mathematical basis of 3D transformations.

Page 5: SE 313 – Computer Graphics

5

What we know already

• Math– Point, vector, magnitude, dot product, cross

product, etc.• Transformations– Translation, rotation, scale– They have a mathematical basis

Page 6: SE 313 – Computer Graphics

6

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

Page 7: SE 313 – Computer Graphics

7

Translation

• How can we move an object?– Add numbers to the coordinates of all of its points

• Explanation on the board

Page 8: SE 313 – Computer Graphics

8

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

Page 9: SE 313 – Computer Graphics

9

Scale

• How can we scale an object (wrt the origin)?– Multiplication!

• Explanation on the board

Page 10: SE 313 – Computer Graphics

10

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

Page 11: SE 313 – Computer Graphics

11

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.

Page 12: SE 313 – Computer Graphics

12

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

Page 13: SE 313 – Computer Graphics

13

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!

Page 14: SE 313 – Computer Graphics

14

Translation as a matrix multiplication?

• Think about it for a minute.

Page 15: SE 313 – Computer Graphics

15

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

Page 16: SE 313 – Computer Graphics

16

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.

Page 17: SE 313 – Computer Graphics

17

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.

Page 18: SE 313 – Computer Graphics

18

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

Page 19: SE 313 – Computer Graphics

19

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

Page 20: SE 313 – Computer Graphics

20

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.

Page 21: SE 313 – Computer Graphics

21

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 blah blah. DON’T CARE! We don’t need them.

Page 22: SE 313 – Computer Graphics

22

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

Page 23: SE 313 – Computer Graphics

23

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)