Linear Transformations & Their Role in Computer Graphics
Linear transformation s map between vector spaces. When we use some method $T$ to produce a vector $\vec v$ in some vector space $V$ from a vector $\vec u$ belonging to a vector space $U$.
Formally:
\[T:U\rightarrow V\]$U$ and $V$ can be the same vector space:
\[U=V=R^2\]These may also be different vector spaces:
\[U=R^3,V=R^2\]An example of this is projecting 3D object to 2D displays.
Why Are These Interesting?
- Graphical Effects
- Scaling an object, rotation may be implemented by matrix and vector multiplication.
- I f an effect is a linear transformation then it is a matrix product.
- If an effect is a matrix product then it is a linear transformation.
Matrices
A quick review of matrices was given. This included their anatomy and methods for multiplication.
Linear Transformation - Definition
- Vector spaces $U$ and $V$ where $U$ may equal $V$.
-
$T$ a mapping from $U$ to $V$.
- $T:V\rightarrow V$
- $T$ is a linear transformation if:
-
$\forall p,q\in U:T(p+q)=T(p)+T(q)$
This means that if we take any two vectors ($p,q$) in the vector space $U$, if we add those two vectors and then apply the mapping $T$ then that should be the same as adding together the mapping on each individual vector.
-
$\forall\alpha\in H,\forall p\in U: T(\alpha p)=\alpha T(p)$
The second condition is that if we take any constant value in the underlying set of numbers we are using to define the vectors, and we take any vector in the vector space; then the result of applying the transformation to the vector multiplied by the constant is the same as applying the transformation to the vector and multiplying the result by the constant.
-
Examples of 2D Effects
-
Scaling by a factor $s\in \Bbb R$ \(\pmatrix{s&0\\0&s}\pmatrix{x\\y}=\pmatrix{sx\\sy}=s\pmatrix{x\\y}\)
-
Rotating anti-clockwise around origin by $\theta^\circ$
\[\begin{align} &\pmatrix{\cos\theta&-\sin\theta\\\sin\theta&\cos\theta}\pmatrix{x\\y}\\ &=\pmatrix{x\cos\theta-y\sin\theta\\x\sin\theta+y\cos\theta} \end{align}\]
Examples of 3D Effects
- Scaling by a factor $s\in \Bbb R$ \(\pmatrix{s&0&0\\0&s&0\\0&0&s}\pmatrix{x\\y\\z}=\pmatrix{sx\\sy\\sz}=s\pmatrix{x\\y\\z}\)
Rotation in 3D is more complex. You wouldn’t typically do this using matrix operations.
Translation
A very basic effect is move an object at $(x,y)$ to a position $(x+p,y+q)$. Similarly in 3D.
The mapping $T:R^2\rightarrow R^2$ defined through:
\[T(x,y)=(x+p,y+q)\]This is not a linear transformation. This is also the same in 3D.
Homogenous Coordinates
Using homogenous coordinate systems we can implement translations by matrix-vector products.
Instead of using $\left(\begin{smallmatrix}x\\y\end{smallmatrix}\right)$ we use $\left(\begin{smallmatrix}x\\y\\1\end{smallmatrix}\right)$:
\[\pmatrix{1&0&p\\0&1&q\\0&0&1}\pmatrix{x\\y\\1}=\pmatrix{x+p\\y+q\\1}\]By adding an extra row and column to the $2\times2$ matrices for scaling and rotation we can implement most effect via $3\times4$ vectors products.
Combining Effects
By multiplying the matrices together we can apply all three effects at the same time.
Care is needed since the outcome of move then scale is not the same as the of scale then move.
3D rotations add additionally complexity.