lecture 04: transform 1
DESCRIPTION
Lecture 04: Transform 1. COMP 175: Computer Graphics February 4, 2014. Geometric Transform. Apply transforms to a hierarchy of objects / vertices… Specifically, translate (T), rotate (R), scale (S). Concepts in Linear Algebra. 3D Coordinate System Vectors and Points in 3D space - PowerPoint PPT PresentationTRANSCRIPT
COMP 175 | COMPUTER GRAPHICS
Remco Chang 1/5904 – Transform 1
Lecture 04:Transform 1
COMP 175: Computer GraphicsFebruary 9, 2016
COMP 175 | COMPUTER GRAPHICS
Remco Chang 2/5904 – Transform 1
Sign up on Google Doc for your in-person grading
Admin
COMP 175 | COMPUTER GRAPHICS
Remco Chang 3/5904 – Transform 1
Apply transforms to a hierarchy of objects / vertices… Specifically, translate (T), rotate (R), scale (S)
Geometric Transform
COMP 175 | COMPUTER GRAPHICS
Remco Chang 4/5904 – Transform 1
3D Coordinate System Vectors and Points in 3D space Dot and Cross products
Matrix notation and manipulation with other matrices, 3D vectors, and 3D points
Homogeneous coordinates (x, y, z, w)
Associativity prosperity of matrix multiplication (But NOT communicative property!!) Associative => (5 + 2) + 1 = 5 + (2 + 1) Commutative => 5 +2 + 1 = 1 + 2 + 5
Matrix transpose and inverse
Concepts in Linear Algebra
COMP 175 | COMPUTER GRAPHICS
Remco Chang 5/5904 – Transform 1
Let’s say I need: 6 apples, 5 cans of soup, 1 box of tissues, 2 bags of chips
4 Stores, A, B, C, and D (Stop and Shop, Shaw’s, Trader Joe’s, and Whole Foods)
Vector and Matrix Notation
1 apple 1 can of soup 1 box of tissue 1 bag of chips
Stop and Shop $0.20 $0.93 $0.64 $1.20
Shaw’s $0.65 $0.82 $0.75 $1.40
Trader Joe’s $0.95 $1.10 $0.52 $3.20
Whole Foods $1.15 $0.20 $1.25 $2.25
COMP 175 | COMPUTER GRAPHICS
Remco Chang 6/5904 – Transform 1
Which store do you go to? Find the total cost from each store Find the minimum of the four stores
More formally, let denote the quantity of item .
Let be the unit price of item at store .
Then:
Shopping Example
q1 q2 q3 q4
A $0.20 $0.93 $0.64 $1.20
B $0.65 $0.82 $0.75 $1.40
C $0.95 $1.10 $0.52 $3.20
D $1.15 $0.20 $1.25 $2.25
Total_A = (0.2 * 6) + (0.93 * 5) + (0.64 * 1) + (1.20 * 2) = 8.89
COMP 175 | COMPUTER GRAPHICS
Remco Chang 7/5904 – Transform 1
: Let’s rewrite that in matrix form:
Matrix Form
q1 q2 q3 q4
A $0.20 $0.93 $0.64 $1.20
B $0.65 $0.82 $0.75 $1.40
C $0.95 $1.10 $0.52 $3.20
D $1.15 $0.20 $1.25 $2.25
For the prices, let’s also rewrite it:
COMP 175 | COMPUTER GRAPHICS
Remco Chang 8/5904 – Transform 1
Determine totalCost vector using row-column multiplication Dot product is the sum of the pairwise multiplications Apply this operation to rows of prices and column of quantities
Using the Matrix Notation
COMP 175 | COMPUTER GRAPHICS
Remco Chang 9/5904 – Transform 1
Each entry in the resulting matrix L is the dot product of a row of M with a column of N:
Does and the same?
Reminder: Matrix Multiplication
COMP 175 | COMPUTER GRAPHICS
Remco Chang 10/5904 – Transform 1
TotalCost_A = (0.2 * 6) + (0.93 * 5) + (0.64 * 1) + (1.20 * 2) = 8.89
Using the Matrix Notation
COMP 175 | COMPUTER GRAPHICS
Remco Chang 11/5904 – Transform 1
What if our price matrix is of the following?
Identity Matrix
COMP 175 | COMPUTER GRAPHICS
Remco Chang 12/5904 – Transform 1
What if our price matrix is of the following?
We call this matrix the “identity matrix”
Identity Matrix
COMP 175 | COMPUTER GRAPHICS
Remco Chang 13/5904 – Transform 1
What if our price matrix is of the following?
Identity Matrix
COMP 175 | COMPUTER GRAPHICS
Remco Chang 14/5904 – Transform 1
What if our price matrix is of the following?
So this is a “scaling matrix”
Identity Matrix
COMP 175 | COMPUTER GRAPHICS
Remco Chang 15/5904 – Transform 1
In this example, notice the first column of the matrix is only affecting the first value of the result
Why is this important??
Note!
COMP 175 | COMPUTER GRAPHICS
Remco Chang 16/5904 – Transform 1
In this example, notice the first column of the matrix is only affecting the first value of the result
So each column acts like a “basis vector”…
Note!
COMP 175 | COMPUTER GRAPHICS
Remco Chang 17/5904 – Transform 1
Suppose we have some matrix, like , and we want to know what it’ll do to a 2D point.
First, we multiply this matrix by two unit basis vectors, the x-axis and the y-axis:
Notice the results are the two columns of the matrix…
So let’s visualize how the x and y axes have been transformed using our matrix
Matrix Multiplication Explained (Visually)
COMP 175 | COMPUTER GRAPHICS
Remco Chang 18/5904 – Transform 1
Original Coordinate System After we apply the transform
Matrix Multiplication Explained (Visually)
COMP 175 | COMPUTER GRAPHICS
Remco Chang 19/5904 – Transform 1
Let’s test the new coordinate system on a new point .
We see what this looks like in the original Cartesian coordinate system:
Matrix Multiplication Explained (Visually)
This demonstrates the concept of “change of basis”. The row vectors of the new matrix define the new basis
COMP 175 | COMPUTER GRAPHICS
Remco Chang 20/5904 – Transform 1
Questions?
COMP 175 | COMPUTER GRAPHICS
Remco Chang 21/5904 – Transform 1
Elemental Transformations: Translation Rotation Scaling Shearing
Of the four, three of them are affine and linear: Rotation, Scaling, and Shearing
One is affine but non-linear Translation
Transformations in Computer Graphics
COMP 175 | COMPUTER GRAPHICS
Remco Chang 22/5904 – Transform 1
Projective Affine Linear⊃ ⊃ Meaning that all linear transforms are also affine
transforms, which are also projective transforms. However, not all affine transforms are linear transforms,
and not all projective transforms are affine. Definitions:
Linear Transform: Preserves all parallel lines Acts on a line to yield either a line or a point The vector [0, 0] is always transformed to [0, 0] Examples: scale and rotate
Definitions of Transformations
COMP 175 | COMPUTER GRAPHICS
Remco Chang 23/5904 – Transform 1
Definitions: Linear Transform:
Preserves parallel lines Acts on a line to yield either a line or a point The vector [0, 0] is always transformed to [0, 0] Examples: scale and rotate
Affine Transform: Preserves parallel lines Acts on a line to yield either a line or a point The vector [0, 0] is NOT always transformed to [0, 0] Examples: translate
Projective Transform: Does NOT preserve parallel lines Acts on a line to yield either a line or a point Examples: perspective camera (assignment 2)
Definitions of Transformations
COMP 175 | COMPUTER GRAPHICS
Remco Chang 24/5904 – Transform 1
Component-wise scalar multiplication of vectors
Where is a scalar, and and
Without using a matrix, we would have: and
What would we do with using a matrix?
2D Scaling
COMP 175 | COMPUTER GRAPHICS
Remco Chang 25/5904 – Transform 1
Component-wise scalar multiplication of vectors
Where is a 2x2 matrix , and and
Now: and
2D Scaling
COMP 175 | COMPUTER GRAPHICS
Remco Chang 26/5904 – Transform 1
Given , what happens to the following 2 vertices of the house?
Y
X 0
1
1
2
2
3 4 5 6 7 8 9 10
3
4
5
6
12
13
23
y
x
ss
2D Scaling, An Example
COMP 175 | COMPUTER GRAPHICS
Remco Chang 27/5904 – Transform 1
Given , what happens to the following?
Uh… Something looks wrong…
2D Scaling, An Example
Y
X 0
1
1
2
2
3 4 5 6 7 8 9 10
3
4
5
6
12
13
26
29
23
y
x
ss
COMP 175 | COMPUTER GRAPHICS
Remco Chang 28/5904 – Transform 1
Given , what happens to the following?
What’s the problem? Lengths of the edges are not preserved! Angles between edges are not preserved!
Except if
2D Scaling, An Example
Y
X 0
1
1
2
2
3 4 5 6 7 8 9 10
3
4
5
6
12
13
26
29
23
y
x
ss
COMP 175 | COMPUTER GRAPHICS
Remco Chang 29/5904 – Transform 1
Rotation of vectors around an angle q, where and
, which means
2D Rotation
COMP 175 | COMPUTER GRAPHICS
Remco Chang 30/5904 – Transform 1
Derive by determining how and should be transformed
= , first column of = , second column of
Thus we obtain :
2D Rotation, Proof 1
COMP 175 | COMPUTER GRAPHICS
Remco Chang 31/5904 – Transform 1
2D Rotation, Proof 2
COMP 175 | COMPUTER GRAPHICS
Remco Chang 32/5904 – Transform 1
1. From the triangle EY’P, 2. So 3. Multiply both sides by : 4. Finally, from the triangle OYE, ,
or 5. Therefore:
2D Rotation, Proof 2
COMP 175 | COMPUTER GRAPHICS
Remco Chang 33/5904 – Transform 1
What would the outcome be? How would you do this in pseudo code?
2D Rotation Example
6q
q
COMP 175 | COMPUTER GRAPHICS
Remco Chang 34/5904 – Transform 1
Result:
2D Rotation Example
6q
Y
X 0
1
1
2
2
3 4 5 6 7 8 9 10
3
4
5
6
q
COMP 175 | COMPUTER GRAPHICS
Remco Chang 35/5904 – Transform 1
For Scaling, we have:
where and , and
For Rotation, we have:
where and , and
Hmmm… Maybe we can start stringing things together one’s becomes another’s More on that later… We’re still missing translation
Recap
COMP 175 | COMPUTER GRAPHICS
Remco Chang 36/5904 – Transform 1
To translate, scale, and rotate vectors we need a function to give a new value of x, and a function to give a new value of y
Examples: Rotation:
These are both of the form:
Since the transforms are given by a system of linear equations, they are called linear transformations, and is represented by the matrix:
Sets of Linear Equations and Matrices
Scaling
COMP 175 | COMPUTER GRAPHICS
Remco Chang 37/5904 – Transform 1
Goal: moving a house from location A to location B:
Pretty easy… Just add 5 to x and 3 to y If there are multiple vertices in the house, apply the
addition to each and every vertex
2D Translation
Y
X 0
1
1
2
2
3 4 5 6 7 8 9 10
3
4
5
6
R 2
A = (2, 3)
Y B = (7, 6)
COMP 175 | COMPUTER GRAPHICS
Remco Chang 38/5904 – Transform 1
Questions?
COMP 175 | COMPUTER GRAPHICS
Remco Chang 39/5904 – Transform 1
How do you multiply a (3x3) matrix by 3D vector?
How do you multiply two 3x3 matrices?
Given this matrix: , what are the 4 basis vectors? How did you find those?
Matrix as a coordinate transform What happens if you have a 2x3 matrix (2 rows, 3 columns) and we
multiply it by a 3D vector? What happens if we have a 3x2 matrix (3 rows, 2 columns) and we
multiply it by a 3D vector?
Refresher
COMP 175 | COMPUTER GRAPHICS
Remco Chang 40/5904 – Transform 1
Questions?
COMP 175 | COMPUTER GRAPHICS
Remco Chang 41/5904 – Transform 1
In matrix notation, this means: where , , and which means: and
2D Translate
dx = 2dy = 3
Y
X 0
1
1
2
2
3 4 5 6 7 8 9 10
3
4
5
6
12
44
Translation: Preserves lengths
(isometric) Preserves angles
(conformal)
COMP 175 | COMPUTER GRAPHICS
Remco Chang 42/5904 – Transform 1
Exercise: consider linear transformations
In matrix form:
Can translation be expressed as a linear transformation?
Think back to the previous translation example…
2D Translation
COMP 175 | COMPUTER GRAPHICS
Remco Chang 43/5904 – Transform 1
Consider the example on the right: Moving a point from (2,3) to (7,6) implies a translation of (5,3)
In matrix form:
Or:
2D Translation
Y
X 0
1
1
2
2
3 4 5 6 7 8 9 10
3 4 5 6
R 2
here = (2, 3)
Y there = (7, 6)
COMP 175 | COMPUTER GRAPHICS
Remco Chang 44/5904 – Transform 1
Let’s rewrite this:
As:
Now can you write this in matrix form in the form of: using the variables: ?
2D Translation
COMP 175 | COMPUTER GRAPHICS
Remco Chang 45/5904 – Transform 1
Intuitively, what we want to write is:
But this doesn’t work because the dimensions don’t line up right! That is, the matrix is 2x3, and the vector is 2x1
But what if…
2D Translation
COMP 175 | COMPUTER GRAPHICS
Remco Chang 46/5904 – Transform 1
Intuitively, what we want to write is:
But this doesn’t work because the dimensions don’t line up right! That is, the matrix is 2x3, and the vector is 2x1
But what if…
2D Translation
COMP 175 | COMPUTER GRAPHICS
Remco Chang 47/5904 – Transform 1
This is huge! Because now we can string together Scaling, Rotation, and Translation
Recall, we had: For Scaling, we have:
For rotation, we have:
Now we add: For translation, we have:
Except that the Translation matrix is slightly bigger… What can we do?
Composite Matrix Transform
COMP 175 | COMPUTER GRAPHICS
Remco Chang 48/5904 – Transform 1
For Scaling, we have:
where
For Rotation, we have:
where
For Translation, we have:
where
Recap
COMP 175 | COMPUTER GRAPHICS
Remco Chang 49/5904 – Transform 1
Questions?
COMP 175 | COMPUTER GRAPHICS
Remco Chang 50/5904 – Transform 1
Question, we just said that we can represent a vertex as in our homogeneous coordinate system.
How do we represent a vector? The same? Or different?
Points vs. Vectors
COMP 175 | COMPUTER GRAPHICS
Remco Chang 51/5904 – Transform 1
As it turns out, we represent vectors differently… For a point, we say: For a vector, we say:
Why do you think that’s the case?
Points vs. Vectors
COMP 175 | COMPUTER GRAPHICS
Remco Chang 52/5904 – Transform 1
For Scaling, we have:
where
For Rotation, we have:
where
For Translation, we have:
where
Find the values of x’, y’ and w’
COMP 175 | COMPUTER GRAPHICS
Remco Chang 53/5904 – Transform 1
What did we just find out?
That a vector can be Scaled Rotated
But NOT Translated…
Which fits our original definition of a vector!
Cool!
COMP 175 | COMPUTER GRAPHICS
Remco Chang 54/5904 – Transform 1
Questions?
COMP 175 | COMPUTER GRAPHICS
Remco Chang 55/5904 – Transform 1
What just happened to creating the Translation matrix? What does it mean to add the extra 1?
This is called Homogeneous Coordinates: add an additional dimension, the w-axis, and an extra coordinate, the w-component Thus 2D->3D (effectively the hyperspace for embedding
2D space)
Uh, What Was That Again?
COMP 175 | COMPUTER GRAPHICS
Remco Chang 56/5904 – Transform 1
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
q
4q
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 57/5904 – Transform 1
Allows expression of all three 2D transforms as 3x3 matrices (Scaling, Rotation, Translation)
We start with the point on the x-y plane, and apply a mapping to bring it to the w-plane in hyperspace:
The resulting coordinates in our new point are different from the original in that:
Homogeneous Coordinates
COMP 175 | COMPUTER GRAPHICS
Remco Chang 58/5904 – Transform 1
Once we have this point , we can apply a homogenized version of our translation matrices to it to get a new point in hyperspace
Finally, we want to obtain the resulting point in 2D-space again, so we perform a reverse mapping to convert from hyperspace back to 2D space:
Homogeneous Coordinates
COMP 175 | COMPUTER GRAPHICS
Remco Chang 59/5904 – Transform 1
It’s obvious that for our purposes, it’s easiest to make So we say is the intersection of the line determined by
with the plane:
Homogeneous Coordinates
To reiterate, the vertex is now represented as: And we represent our
vertex on the hyperplane
COMP 175 | COMPUTER GRAPHICS
Remco Chang 60/5904 – Transform 1
Questions?