Applications of Computer Graphics
Here, we’re going to work with points in /, and focus on how we can move these points in space. For example, how can we rotate points in space? Translate them?
Hint: This can be accomplished through matrix multiplication!
We’ll start by treating points in / as either / vectors . We can represent collections of them, called pictures, as a matrix
We’ll also treat “movements” in space as a matrix , such that we can transform points by taking . We can also apply this movement to an entire picture by multiplying
2D Graphics
A linear transformation is a function such that
- ,
- For ,
If is any matrix, then we can use it to define a linear transformation function . And in fact, every linear transformation has a corresponding matrix form.
Theorem: Matrices of Linear Transformations
If is a linear transformation, then there is a matrix such that for all .
To find it, we can find column by column as so:
Where is the standard basis vector for , the vector with 1 in the component and 0’s everywhere else.
Example: Matrices of Linear Transformations (1)
Counterclockwise rotation about the origin by degrees in is a linear transformation .
We can find its standard matrix column by column:
This gives us matrix
Note that we can also combine common linear transformations to build more complex transformations! Consider the following example.
Note that what combining matrices by multiplying them, we should multiply right to left in order of the operation we want to perform first!
Example: Compositions of Linear Transformations
Find the matrix for reflection through the -axis.
What about reflection through the line that makes an angle of with the positive -axis?
Instead of doing heavy math, we can actually just combine linear transformations! Let’s first rotate to the origin, then reflect, then rotate back!
- Rotate by radians
- Reflect across the -axis
- Rotate by radians
Finding and multiplying the matrices for these steps will give us our final transformation!
Below, we can find some common linear transformations in .
-
Say we wanted to perform a CCW rotation about the origin by radians. Our transformation matrix is
-
Say we wanted to reflect a line across the -axis. Then, we have transformation matrix
-
Say we wanted to translate a point, or in other words, shift it by a fixed amount. Such a translation is not possible with a matrix, but it is with a matrix!
We can represent our vectors in homogeneous coordinates, where we add an extra 1 component. So for any 2-dimensional vector, we consider them to be , and can form a translation matrix as follows:
Compositions of Transformations with Translation
Note that to combine translations with other transformations in , we need to convert our transformations to a corresponding matrix in homogeneous coordinates! We can do this by adding a 1 in the bottom-right diagonal, all others 0.
So for example, a rotation compatible with translations is
Example: Compositions of Linear Transformations (2)
Suppose we want to do a CCW rotation about the point by some angle . Find a matrix for this operation.
We can find the matrix as follows:
- Translate by
- Rotate about the origin by
- Translate by
We find this as
If we wanted to apply this to a point , we would convert this to homogenoeus coordinates , then take the product!
3D Graphics
Like in the 2D case, we will represent the 3D point in homogeneous coordinates .
Translations can be done by multiplying the matrix
Rotations in 3D are considerably more complex than that of the 2D case. Rotations in 3D have an axis (line) and an angle. All points are rotated around this axis such that the orthogonal vector from the line to the point, and the orthogonal vector from the line to the new point, form the angle given.
If the axis goes through the origin, then the rotation is a linear transformation and can be given by a matrix.
Example: Z-Axis Rotation in 3D
Consider the rotation around the -axis by radians.
We can find the standard matrix by transformating the standard basis vectors.
It’s important to realize that our rotation is actually a rotation in the plane! The z-coordinate does not change.
This gives us standard matrix
For homogeneous coordinates, we have
When we specify an axis of rotation, we’ll also specify a direction on that axis indicating how we should rotate about that axis. Then, we will follow the right hand rule convention for rotations.
In this convention, we place our thumb in the direction of the axis, and the way our fingers curl defines the orientation of the rotation.
We have the following rotations about the standard axes:
But what if we want to rotate about an axis that is not one of the standard axes? Well, we could combine rotations to obtain a rotation which is “effectively” a rotation about this axis!
Like in the 2D case, we can combine our transformations to obtain more complex transformations!
Example: Compositions of Transformations
Suppose we want to rotate about the line through that is parallel to the -axis (with same orientation) by an angle of .
We can find our standard matrix by first translating to the origin, rotating about , then translating back to our point!
Perspective Projection in 3D
In a 3D scene, how can we render it to a 2D image?
We could simply project these points onto a “viewing” plane, but this will give us a very flat image, which fails to give us a sense of depth!
In fact, this happens because our eyes have depth cues that simple projection doesn’t preserve. These include:
- Objects that are further are smaller
- Parallel lines converge at the horizon
This is where perspective projection comes in! Given our view, this projection transforms points so that points further away appear closer in nature!
Consider a view at which is looking down at the plane. Then, for any point, we want to find its projection on the plane , where the projection is co-linear with our viewing point and input point.
We can find this as the point on the plane intersecting the line starting at
We wish to find the point such that , so we solve such that
This gives us the transformed point in perspective projection!
Now, how do we express this in matrix form?
The problem is, this is a nonlinear transformation!
However, interestingly enough, we can find the the linear transformation
After which, if we divide by the coordinate, we’ll obtain our perspective projection!
So, our perspective projection matrix is
Where for any point, we convert it to homogeneous coordinates , and after multiplying , we divide all entries by the coordinate (sometimes called post-processing).
Note that this matrix assumes that our view is at and is looking at the origin! If our view has a different orientation, we can shift it to the -axis, and then change everything back!
Example: Perspective Projection
Consider the cube with vertices . Consider perspective projection from .
Let’s apply perspective projection on .
Our transformation was !