lecture 10: transform 3
DESCRIPTION
Lecture 10: Transform 3. COMP 175: Computer Graphics October 6, 2011. Refresher. Write out the basic forms for a 2D: Scaling matrix Rotation matrix Translation matrix Why is Translation transform affine but not linear? What are homogeneous coordinates? - PowerPoint PPT PresentationTRANSCRIPT
COMP 175 | COMPUTER GRAPHICS
Remco Chang 1/5110 – Transform 3
Lecture 10:
Transform 3
COMP 175: Computer GraphicsOctober 6, 2011
COMP 175 | COMPUTER GRAPHICS
Remco Chang 2/5110 – Transform 3
Write out the basic forms for a 2D: Scaling matrix Rotation matrix Translation matrix
Why is Translation transform affine but not linear?
What are homogeneous coordinates? What is the basic form of a 3D point in homogeneous
coordinates? What about a 3D vector?
Refresher
COMP 175 | COMPUTER GRAPHICS
Remco Chang 3/5110 – Transform 3
Window Transformations: Given a window (rectangle) with bounding coordinates Create a matrix that can both move and scale this matrix
so that the new bounding box is
Exercise
COMP 175 | COMPUTER GRAPHICS
Remco Chang 4/5110 – Transform 3
This is important! Think about what this means for 2D graphics and visualization.
In 3D graphics, this is also commonly used to create viewports. So this matrix is known as the “window-to-viewport” transformation
Exercise - Solution
COMP 175 | COMPUTER GRAPHICS
Remco Chang 5/5110 – Transform 3
Questions?
COMP 175 | COMPUTER GRAPHICS
Remco Chang 6/5110 – Transform 3
For Scaling, we have:
where
If I want to go backwards, that is, if I was given x’, y’, how would I find x and y? In other words, I want:
Find
Matrix Inverse
COMP 175 | COMPUTER GRAPHICS
Remco Chang 7/5110 – Transform 3
If I want to go backwards, that is, if I was given x’, y’, how would I find x and y? In other words, I want:
Find
If we look at it at a component level: , then
Matrix Inverse
COMP 175 | COMPUTER GRAPHICS
Remco Chang 8/5110 – Transform 3
If we look at it at a component level: , then
Let’s put that back into a matrix form:
where
Matrix Inverse
COMP 175 | COMPUTER GRAPHICS
Remco Chang 9/5110 – Transform 3
Notice that if we were to multiply the two together: or , we get back the identity matrix
In other words:
Matrix Inverse
COMP 175 | COMPUTER GRAPHICS
Remco Chang 10/5110 – Transform 3
Definition:
Inverting composed matrices:
Note,
It is important to note that a matrix is not always invertable. A matrix will not be invertible if: It is not a square matrix ( matrix) It has row/column of all zeros (because the row/col can be deleted) If any row/col is a multiple of any other row/col (if a row is not
linearly independent) Matrices for Rotation, Scaling, Translation (using
homogeneous coordinates) will always have inverses!
Matrix Inverse
COMP 175 | COMPUTER GRAPHICS
Remco Chang 11/5110 – Transform 3
Is to think of an inverse as an “undo” For example, if A scales by a factor of 2 and rotates
135 degrees, then A-1 will rotate by -135 degrees and scale by 0.5
One Way To Think About Inverses…
Rectangle(B) A*B A-1*B A-1*A*B
COMP 175 | COMPUTER GRAPHICS
Remco Chang 12/5110 – Transform 3
We have found the inverse matrix of a Scaling matrix.
Let’s find the inverse matrix of a Translation matrix
Finding Inverse Matrices…
COMP 175 | COMPUTER GRAPHICS
Remco Chang 13/5110 – Transform 3
This is pretty simple, we just want to “subtract” the change…
What about Rotation matrix?
Finding Inverse Matrices…
COMP 175 | COMPUTER GRAPHICS
Remco Chang 14/5110 – Transform 3
Regular Rotation Matrix:
Inverse Rotation Matrix:
Inverse Rotation Matrix
COMP 175 | COMPUTER GRAPHICS
Remco Chang 15/5110 – Transform 3
For Scaling, we have:
where
For Rotation, we have:
where
For Translation, we have:
where
Recap of Inverses
COMP 175 | COMPUTER GRAPHICS
Remco Chang 16/5110 – Transform 3
Questions?
COMP 175 | COMPUTER GRAPHICS
Remco Chang 17/5110 – Transform 3
What is the transpose of a matrix A?
It’s making the rows of the matrix its columns, and its columns become rows Or, you can think of it as: “turning the matrix by 90
degrees
Matrix Transpose
COMP 175 | COMPUTER GRAPHICS
Remco Chang 18/5110 – Transform 3
The inverse of a Rotation Matrix is the same as its transpose . In other words,
Let’s prove this… First, we note the properties of : Columns are orthogonal to each other (e.g., Columns represent unit vectors:
Let’s multiply : =
Neat Fact about Rotation Matrix
COMP 175 | COMPUTER GRAPHICS
Remco Chang 19/5110 – Transform 3
Let’s multiply : =
Based on our rules, the right hand side comes out to: , which is the identity matrix. This means that , by definition,
Neat Fact about Rotation Matrix
COMP 175 | COMPUTER GRAPHICS
Remco Chang 20/5110 – Transform 3
Questions?
COMP 175 | COMPUTER GRAPHICS
Remco Chang 21/5110 – Transform 3
For Scaling, we have:
For Rotation, we have:
For Translation, we have:
Composition of Transformations!
COMP 175 | COMPUTER GRAPHICS
Remco Chang 22/5110 – Transform 3
So, if I want to combine the 3 transformations…
This means:
Composition of Transformations!
COMP 175 | COMPUTER GRAPHICS
Remco Chang 23/5110 – Transform 3
Recall that matrix operations are associative. Meaning that: (1+2)+3 = 1+(2+3),
But it is not commutative: 1+2+3 3+2+1
This means that I can pre-multiply , so that , where
Composition of Transformations!
COMP 175 | COMPUTER GRAPHICS
Remco Chang 24/5110 – Transform 3
Remember, ORDER MATTERS!!
So
For Example….
Composition of Transformations!
COMP 175 | COMPUTER GRAPHICS
Remco Chang 25/5110 – Transform 3
Not commutative
Translate by =6, =0 then rotate by 45º
Rotate by 45º then translate by =6, =0
0 1
1
2
2
3 4 5 6 7 8 9 10
3
4
5
6
Y
X 0
1
1
2
2
3 4 5 6 7 8 9 10
3
4
5
6
COMP 175 | COMPUTER GRAPHICS
Remco Chang 26/5110 – Transform 3
Start: Goal:
Important concept: Make the problem simpler Translate object to origin first, scale , rotate, and translate
back
Apply to all vertices
Composition (an example) (2D)Rotate 90Uniform Scale 3xBoth around object’s center,not the origin
COMP 175 | COMPUTER GRAPHICS
Remco Chang 27/5110 – Transform 3
Composition (an example) (2D) (2/2)
But what if we mixed up the order? Let’s try
Oops! We managed to scale it properly but when we rotated it we rotated the object about the origin, not its own center, shifting its position…Order Matters!
http://www.cs.brown.edu/exploratories/freeSoftware/repository/edu/brown/cs/exploratories/applets/transformationGame/transformation_game_guide.html (Transformations applet)
COMP 175 | COMPUTER GRAPHICS
Remco Chang 28/5110 – Transform 3
Questions?
COMP 175 | COMPUTER GRAPHICS
Remco Chang 29/5110 – Transform 3
Recall that:
Why is that?
For example: Let , then In terms of operations, it makes sense:
1) Rotate 2) Translate
In reverse, I would want to 1) Reverse Translate 2) Reverse Rotate
Inverse Composite Matrix
COMP 175 | COMPUTER GRAPHICS
Remco Chang 30/5110 – Transform 3
What is the inverse of a sequence of transformations?
Inverse of a sequence of transformations is the composition of the inverses of each transformation in reverse order
Say from our from our previous example we wanted do the opposite, what will our sequence look like?
We still translate to origin first, then translate back at the end!
Inverses Revisited
COMP 175 | COMPUTER GRAPHICS
Remco Chang 31/5110 – Transform 3
Questions?
COMP 175 | COMPUTER GRAPHICS
Remco Chang 32/5110 – Transform 3
We understand linear transformations as changing the position of vertices relative to the standard axes
Can also think of transforming the coordinate axes themselves
Just as in matrix composition, be careful of which order you modify your coordinate system
Transforming Coordinate Axes
Rotation Scaling Translation
COMP 175 | COMPUTER GRAPHICS
Remco Chang 33/5110 – Transform 3
We have been doing everything in 2D. What happens in 3D Cartesian Coordinate System?
Mapping It to 3D
COMP 175 | COMPUTER GRAPHICS
Remco Chang 34/5110 – Transform 3
For Scaling, we have:
For Rotation, we have:
For Translation, we have:
(will be explained)
Composition of Transformations!
COMP 175 | COMPUTER GRAPHICS
Remco Chang 35/5110 – Transform 3
Rotation by angle around v =
Here’s a not so friendly rotation matrix:
This is called the coordinate form of Rodrigues’s formula
Let’s try a different way…
Rotation
COMP 175 | COMPUTER GRAPHICS
Remco Chang 36/5110 – Transform 3
Every rotation can be represented as the composition of 3 different angles of CLOCKWISE rotation around 3 axes, namely -axis in the plane by -axis in the plane by -axis in the plane by
Also known as Euler angles, makes the problem of rotation much easier to deal with
: rotation around the axis, : rotation about the axis, : rotation about the axis You can compose these matrices to form a composite rotation matrix
Rotating axis by axis (1/2)
COMP 175 | COMPUTER GRAPHICS
Remco Chang 37/5110 – Transform 3
It would still be difficult to find the 3 angles to rotate by given arbitrary axis and specified angle
Solution? Make the problem easier
Step 1: Find a to rotate around axis to put in the plane
Step 2: Then find a to rotate around the axis to align with theaxis
Step 3: Rotate by around axis = axis
Step 4: Finally, undo the alignment rotations (inverse)
Rotation Matrix:
Rotating axis by axis (2/2)
COMP 175 | COMPUTER GRAPHICS
Remco Chang 38/5110 – Transform 3
Inverses are once again parallel to their 2D versions…
Composition works exactly the same way…
Inverses and Composition in 3D!
Transformation Matrix Inverse
Scaling
Rotation
Translation
COMP 175 | COMPUTER GRAPHICS
Remco Chang 39/5110 – Transform 3
Let’s take some 3D object, say a cube, centered at (2,2,2) Rotate in object’s space by 30 around axis, 60 around and 90around Scale in object space by 1 in the , 2 in the , 3 in the Translate by (2,2,4) Transformation Sequence:, where translates to
Example in 3D!
39
COMP 175 | COMPUTER GRAPHICS
Remco Chang 40/5110 – Transform 3
Questions?
COMP 175 | COMPUTER GRAPHICS
Remco Chang 41/5110 – Transform 3
We’re going to use Gauss-Jordan elimination Finding A-1 with Gauss-Jordan elimination is done by augmenting A
with I to get [A|I], then reducing the new matrix into reduced row echelon form (rref) to get a new matrix. This new matrix will be of the form [I|A-1]
What does rref really mean? If a row does not consist entirely of zeros, then the first nonzero number in the row is a
1. (Call this a leading 1) If there are any rows that consist entirely of zeros, then they are grouped together at
the bottom of the matrix. If any two successive rows do not consist entirely of zeros, the leading 1 in the lower
row occurs farther to the right than the leading 1 in the higher row Each column that contains a leading 1 has zeros everywhere else.
How to Invert a Matrix
COMP 175 | COMPUTER GRAPHICS
Remco Chang 42/5110 – Transform 3
To transform a matrix into rref we are allowed to perform any of the three elementary row operations. These are: Multiply a row by a nonzero constant Interchange two rows Add a multiple of one row to another row
How to Invert a Matrix
COMP 175 | COMPUTER GRAPHICS
Remco Chang 43/5110 – Transform 3
Given: , let’s find :
1. Augment this with the identity:
2. Row operation 1: multiply row 1 by 1/11
3. Row operation 3: multiply row 1 by -17 and add it to row 2:
How to Invert a Matrix, Example
COMP 175 | COMPUTER GRAPHICS
Remco Chang 44/5110 – Transform 3
4. Row operation 1, multiply row 2 by –11/12
5. Row operation 3: multiply row 2 by –13/11 and add to row 1
6. Therefore:
How to Invert a Matrix, Example
COMP 175 | COMPUTER GRAPHICS
Remco Chang 45/5110 – Transform 3
Questions?
COMP 175 | COMPUTER GRAPHICS
Remco Chang 46/5110 – Transform 3
The application of matrices in the row vector notation is executed in the reverse order of applications in the column vector notation:
Column format: vector follows transformation matrix:
Row format: vector precedes matrix and is post-multiplied by it:
By convention, we always use Column Format
Addendum – Matrix Notation
COMP 175 | COMPUTER GRAPHICS
Remco Chang 47/5110 – Transform 3
Uh… A problem:
While:
Addendum – Matrix Notation
COMP 175 | COMPUTER GRAPHICS
Remco Chang 48/5110 – Transform 3
In order for both types of notations to yield the same result, a matrix in the row system must be the transpose of the matrix in the column system Recall:
In order to make the two notations line up:
Be careful! Different textbooks and different graphics packages use different notations! First understand which one they use!!
Addendum – Matrix Notation
COMP 175 | COMPUTER GRAPHICS
Remco Chang 49/5110 – Transform 3
Questions?
COMP 175 | COMPUTER GRAPHICS
Remco Chang 50/5110 – Transform 3
Shearing refers to the “sliding” or “skewing” effect
Addendum: Shearing / Skewing
Y
X 0
1
1
2
2
3 4 5 6 7 8 9 10
3
4
5
6
4
Squares become parallelograms. E.g., x-coordinates skew to the right, y-coordinates stay the same.
Consider the basis vectors for the y-axis That means we’re turning the
90 degree angle between x- and y- axes into .
2D non-Homogeneous
COMP 175 | COMPUTER GRAPHICS
Remco Chang 51/5110 – Transform 3
Questions?