Set your presentation theme:
Black (default) -
White -
League -
Sky -
Beige -
Simple
Serif -
Blood -
Night -
Moon -
Solarized
H:
Jean Pierre Charalambos
Universidad Nacional de Colombia
Presentation best seen online
See also the source code
H:
- Intro
- Linear transformations
- Scaling, rotation & shearing
- Affine transformations
- Homogeneous space
- Translation
- Scaling, rotation & shearing revisited
- Inversion
- Projections
- Orthographic
- Perspective
- References
- Annex: Matrix orthogonality
H:
- Affine transformations are key to develop:
- Read carefully this presentation & these references if you need more detailed explanations:
- Affine transformations are found in 3D Math primer for Graphics and Game Development – chs. 8 & 9
- Projections matrices are found in OpenGL projection matrix
- 3D Rotations methods
- Euler angles (discussed here)
- Matrix orthogonality (discussed here)
- Quaternions (best method and the one supported in nub, not yet included in this presentation but discussed in 3D Math primer for Graphics and Game Development – ch. 10)
N:
- Standard = Canonical
H:
Property 1
Property 2
Observation 1: Matrix multiplication is always linear
Observation 2: Translation is a nonlinear transformation
V:
`$x'= sx*x$`
`$y'= sy*y$`
`$\begin{bmatrix} x' \cr y' \cr \end{bmatrix} = \begin{bmatrix} sx & 0 \cr 0 & sy \cr \end{bmatrix} \bullet \begin{bmatrix} x \cr y \cr \end{bmatrix} $`
N:
- mirroring and reflections are missed
V:
`$x'= sx*x$`
`$y'= sy*y$`
`$z'= sz*z$`
`$\begin{bmatrix} x' \cr y' \cr z' \cr \end{bmatrix} = \begin{bmatrix} sx & 0 & 0 \cr 0 & sy & 0 \cr 0 & 0 & sz \cr \end{bmatrix} \bullet \begin{bmatrix} x \cr y \cr z \cr \end{bmatrix} $`
N:
- mirroring and reflections are missed
V:
V:
`$\begin{bmatrix} x' \cr y' \cr \end{bmatrix} = \begin{bmatrix} cos\beta & -sin \beta \cr sin\beta & cos \beta \cr \end{bmatrix} \bullet \begin{bmatrix} x \cr y \cr \end{bmatrix} $`
V:
`$\begin{bmatrix} x' \cr y' \cr z' \cr \end{bmatrix} = \begin{bmatrix} cos\beta & -sin \beta & 0 \cr sin\beta & cos \beta & 0 \cr 0 & 0 & 1 \cr \end{bmatrix} \bullet \begin{bmatrix} x \cr y \cr z \cr \end{bmatrix} $`
V:
`$\begin{bmatrix} x' \cr y' \cr z' \cr \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \cr 0 & cos\beta & -sin \beta \cr 0 & sin\beta & cos \beta \cr \end{bmatrix} \bullet \begin{bmatrix} x \cr y \cr z \cr \end{bmatrix} $`
V:
`$\begin{bmatrix} x' \cr y' \cr z' \cr \end{bmatrix} = \begin{bmatrix} cos\beta & 0 & sin \beta \cr 0 & 1 & 0 \cr -sin\beta & 0 & cos \beta \cr \end{bmatrix} \bullet \begin{bmatrix} x \cr y \cr z \cr \end{bmatrix} $`
V:
`$x'= x + h*y$`
`$y'=y$`
`$\begin{bmatrix} x' \cr y' \cr \end{bmatrix} = \begin{bmatrix} 1 & h \cr 0 & 1 \cr \end{bmatrix} \bullet \begin{bmatrix} x \cr y \cr \end{bmatrix} $`
V:
`$x'= x$`
`$y'=y + h*x$`
`$\begin{bmatrix} x' \cr y' \cr \end{bmatrix} = \begin{bmatrix} 1 & 0 \cr h & 1 \cr \end{bmatrix} \bullet \begin{bmatrix} x \cr y \cr \end{bmatrix} $`
V:
`$x'=x+az$`
`$y'=y+bz$`
`$z'=z$`
`$\begin{bmatrix} x' \cr y' \cr z' \cr \end{bmatrix} = \begin{bmatrix} 1 & 0 & a \cr 0 & 1 & b \cr 0 & 0 & 1 \cr \end{bmatrix} \bullet \begin{bmatrix} x \cr y \cr z \cr \end{bmatrix} $`
V:
...don't forget
H:
`$x'= x + dx$`
`$y'=y + dy$`
`$\begin{bmatrix} x' \cr y' \cr \end{bmatrix} = \begin{bmatrix} dx \cr dy \cr \end{bmatrix} + \begin{bmatrix} x \cr y \cr \end{bmatrix} $`
V:
Linear transformations
V:
Homogeneous w-coordinate:
Homogeneous space
In general:
V:
In general:
V:
`$x'= x + dx$`
`$y'=y + dy$`
`$w'=w=1$`
`$\begin{bmatrix} x' \cr y' \cr w' \cr \end{bmatrix} = \begin{bmatrix} 1 & 0 & dx \cr 0 & 1 & dy \cr 0 & 0 & 1 \cr \end{bmatrix} \bullet \begin{bmatrix} x \cr y \cr w \cr \end{bmatrix} $`
V:
`$x'= x + dx$`
`$y'=y + dy$`
`$z'=z + dz$`
`$w'=w=1$`
`$\begin{bmatrix} x' \cr y' \cr z' \cr w' \cr \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & dx \cr 0 & 1 & 0 & dy \cr 0 & 0 & 1 & dz \cr 0 & 0 & 0 & 1 \cr \end{bmatrix} \bullet \begin{bmatrix} x \cr y \cr z \cr w \cr \end{bmatrix} $`
V:
`$x'=x+az$`
`$y'=y+bz$`
`$z'=z$`
`$w'=w=1$`
`$\begin{bmatrix} x' \cr y' \cr z' \cr w' \cr \end{bmatrix} = \begin{bmatrix} 1 & 0 & a & 0 \cr 0 & 1 & b & 0 \cr 0 & 0 & 1 & 0 \cr 0 & 0 & 0 & 1 \cr \end{bmatrix} \bullet \begin{bmatrix} x \cr y \cr z \cr w \cr \end{bmatrix} $`
V:
`$x'= sx*x$`
`$y'= sy*y$`
`$z'= sz*z$`
`$w'=w=1$`
`$\begin{bmatrix} x' \cr y' \cr z' \cr w' \cr \end{bmatrix} = \begin{bmatrix} sx & 0 & 0 & 0 \cr 0 & sy & 0 & 0 \cr 0 & 0 & sz & 0 \cr 0 & 0 & 0 & 1 \cr \end{bmatrix} \bullet \begin{bmatrix} x \cr y \cr z \cr w \cr \end{bmatrix} $`
V:
`$w'=w=1$`
`$\begin{bmatrix} x' \cr y' \cr z' \cr w' \cr \end{bmatrix} = \begin{bmatrix} cos\beta & -sin \beta & 0 & 0 \cr sin\beta & cos \beta & 0 & 0 \cr 0 & 0 & 1 & 0 \cr 0 & 0 & 0 & 1 \cr \end{bmatrix} \bullet \begin{bmatrix} x \cr y \cr z \cr w \cr \end{bmatrix} $`
V:
`$w'=w=1$`
`$\begin{bmatrix} x' \cr y' \cr z' \cr w' \cr \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \cr 0 & cos\beta & -sin \beta & 0 \cr 0 & sin\beta & cos \beta & 0 \cr 0 & 0 & 0 & 1 \cr \end{bmatrix} \bullet \begin{bmatrix} x \cr y \cr z \cr w \cr \end{bmatrix} $`
V:
`$w'=w=1$`
`$\begin{bmatrix} x' \cr y' \cr z' \cr w' \cr \end{bmatrix} = \begin{bmatrix} cos\beta & 0 & sin \beta & 0 \cr 0 & 1 & 0 & 0 \cr -sin\beta & 0 & cos \beta & 0 \cr 0 & 0 & 0 & 1 \cr \end{bmatrix} \bullet \begin{bmatrix} x \cr y \cr z \cr w \cr \end{bmatrix} $`
V:
Let
Let
V:
Transformation | Direct | Inverted |
---|---|---|
Translation | ||
Shearing | ||
Scaling | ||
Rotation |
H:
[Orthographic Volume and Normalized Device Coordinates (NDC)](http://www.songho.ca/opengl/gl_projectionmatrix.html#ortho)Let
V:
View volume: Re-mapping a variable among ranges (general case)
|---------------*---------| -> |-------------------*--------------|
min u max min' u' max'
The linear conversion is given by:
$$u' = min'+(u-min)(\Delta u')/(\Delta u)$$
where $\Delta u=max-min$
, and $\Delta u'=max'-min'$
which may be re-written as:
$$u' = uS_u + T_u$$
$$S_u=\Delta u'/\Delta u$$
$$T_u=(min'\Delta u - min\Delta u')/\Delta u$$
V:
|---------------*---------| -> |-------------------*--------------|
min u max -1 u' 1
$$u' = uS_u + T_u$$
$$S_u=2/(max-min)$$
$$T_u=-(max+min)/(max-min)$$
V:
`$$u' = uS_u + T_u$$`
`$\begin{bmatrix} x_c \cr y_c \cr z_c \cr w_c \cr \end{bmatrix} = \begin{bmatrix} S_{x_e} & 0 & 0 & T_{x_e} \cr 0 & S_{y_e} & 0 & T_{y_e} \cr 0 & 0 & S_{z_e} & T_{z_e} \cr 0 & 0 & 0 & 1 \cr \end{bmatrix} \bullet \begin{bmatrix} x_e \cr y_e \cr z_e \cr w_e(=1) \cr \end{bmatrix} $`
`$P_c = Ortho(S_{x_e/y_e/z_e},T_{x_e/y_e/z_e}) \bullet P_e$`
V:
`$$u' = uS_u + T_u$$` `$$S_u=2/(max-min)$$` `$$T_u=-(max+min)/(max-min)$$`
`$\begin{bmatrix} x_c \cr y_c \cr z_c \cr w_c \cr \end{bmatrix} = \begin{bmatrix} 2 \above 1pt (r-l) & 0 & 0 & -(r+l) \above 1pt (r-l) \cr 0 & 2 \above 1pt (t-b) & 0 & -(t+b) \above 1pt (t-b) \cr 0 & 0 & -2 \above 1pt (f-n) & -(f+n) \above 1pt (f-n) \cr 0 & 0 & 0 & 1 \cr \end{bmatrix} \bullet \begin{bmatrix} x_e \cr y_e \cr z_e \cr w_e(=1) \cr \end{bmatrix} $`
`$P_c = Ortho(l,r,b,t,n,f) \bullet P_e$`
V:
Adapted from [ortho](https://p5js.org/reference/#/p5/ortho)V:
Example code
var sketch = function( p ) {
p.setup = function() {
p.createCanvas(600, 600, p.WEBGL);
// define an orthographic matrix projection
p.ortho(-p.width / 2, p.width / 2, p.height / 2, -p.height / 2, 0, 1000);
};
p.draw = function() {
p.background(100);
p.orbitControl(); // interactively modifies the view matrix with the mouse
p.strokeWeight(2);
p.stroke(255, 0, 0);
p.fill(0, 255, 255, 125);
for (var i = -1; i < 2; i++) {
for (var j = -2; j < 3; j++) {
p.push(); // saves current matrix transform (ortho * view)
p.translate(i * 160, 0, j * 160); // same as: ortho * view * translate
p.box(80, 80, 80);
p.pop(); // restores the top of the matrix stack: ortho * view
}
}
};
};
V:
`$$u' = uS_u + T_u$$` `$$S_u=2/(max-min)$$` `$$T_u=-(max+min)/(max-min)$$`
\begin{bmatrix} 1 \above 1pt r & 0 & 0 & 0 \cr 0 & 1 \above 1pt t & 0 & 0 \cr 0 & 0 & -2 \above 1pt (f-n) & -(f+n) \above 1pt (f-n) \cr 0 & 0 & 0 & 1 \cr \end{bmatrix} \bullet \begin{bmatrix} x_e \cr y_e \cr z_e \cr w_e(=1) \cr \end{bmatrix} $`
`$P_c= Ortho(r,t,n,f) \bullet P_e$`
V:
[Perspective Frustum and Normalized Device Coordinates (NDC)](http://www.songho.ca/opengl/gl_projectionmatrix.html#perspective)Let
V:
Top view of frustum$${x_p\above 1pt x_e}= {-n\above 1pt z_e}$$
$$x_p= {nx_e\above 1pt -z_e}$$
V:
Side view of frustum$${y_p\above 1pt y_e}= {-n\above 1pt z_e}$$
$$y_p= {ny_e\above 1pt -z_e}$$
V:
`$$x_p= {nx_e\above 1pt -z_e},y_p= {ny_e\above 1pt -z_e}$$`
which means ${\color{red} {w_c}}=-z_e$
\begin{bmatrix} . & . & . & . \cr . & . & . & . \cr . & . & . & . \cr 0 & 0 & {\color{red} {-1}} & 0 \cr \end{bmatrix} \bullet \begin{bmatrix} x_e \cr y_e \cr z_e \cr w_e(=1) \cr \end{bmatrix} $$`
V:
`$${\color{green} {x_p}}= {nx_e\above 1pt -z_e},{\color{green} {y_p}}= {ny_e\above 1pt -z_e},w_c=-z_e$$`
\begin{bmatrix} 2 \above 1pt (r-l) & 0 & 0 & -(r+l) \above 1pt (r-l) \cr 0 & 2 \above 1pt (t-b) & 0 & -(t+b) \above 1pt (t-b) \cr . & . & . & . \cr . & . & . & . \cr \end{bmatrix} \bullet \begin{bmatrix} {\color{green} {x_p}} \cr {\color{green} {y_p}} \cr z_e \cr w_e(=1) \cr \end{bmatrix} $$`
solving for ${\color{blue} {x_n,y_n}}$
we get:
${\color{blue} {x_n}}= {2{\color{green} {x_p}}\above 1pt r-l}-{r+l\above 1pt r-l},{\color{blue} {y_n}} = {2{\color{green} {y_p}}\above 1pt t-b}-{t+b\above 1pt t-b}$
since
${\color{blue} {x_n}}={x_c\above 1pt w_c}$
and
${\color{blue} {y_n}}={y_c\above 1pt w_c}$
, solving for
${\color{red} {x_c,y_c}}$
in terms of
$x_e,y_e,z_e$
, we get:
${\color{red} {x_c}}= {2nx_e\above 1pt r-l}+{(r+l)z_e\above 1pt r-l},{\color{red} {y_c}}= {2ny_e\above 1pt t-b}+{(t+b)z_e\above 1pt t-b}$
V:
`$${\color{red} {x_c}}= {2nx_e\above 1pt r-l}+{(r+l)z_e\above 1pt r-l},{\color{red} {y_c}}= {2ny_e\above 1pt t-b}+{(t+b)z_e\above 1pt t-b},w_c=-z_e$$`
\begin{bmatrix} 2n \above 1pt r-l & 0 & r+l \above 1pt r-l & 0 \cr 0 & 2n \above 1pt t-b & t+b \above 1pt t-b & 0 \cr . & . & . & . \cr 0 & 0 & -1 & 0 \cr \end{bmatrix} \bullet \begin{bmatrix} x_e \cr y_e \cr z_e \cr w_e(=1) \cr \end{bmatrix} $`
V:
\begin{bmatrix} 2n \above 1pt r-l & 0 & r+l \above 1pt r-l & 0 \cr 0 & 2n \above 1pt t-b & t+b \above 1pt t-b & 0 \cr 0 & 0 & {\color{green} A} & {\color{green} B} \cr 0 & 0 & -1 & 0 \cr \end{bmatrix} \bullet \begin{bmatrix} x_e \cr y_e \cr z_e \cr w_e(=1) \cr \end{bmatrix} $`
`$z_n=z_c/w_c={Az_e+Bw_e\above 1pt -z_e}={Az_e+B\above 1pt -z_e}$`
To find
V:
\begin{bmatrix} 2n \above 1pt r-l & 0 & r+l \above 1pt r-l & 0 \cr 0 & 2n \above 1pt t-b & t+b \above 1pt t-b & 0 \cr 0 & 0 & -(f+n) \above 1pt f-n & -2fn \above 1pt f-n \cr 0 & 0 & -1 & 0 \cr \end{bmatrix} \bullet \begin{bmatrix} x_e \cr y_e \cr z_e \cr w_e(=1) \cr \end{bmatrix} $`
`$P_c = Persp(l,r,b,t,n,f) \bullet P_e$`
V:
Comparison of Depth Buffer PrecisionsV:
`$$l=-r$$` `$$b=-t$$`
`$\begin{bmatrix} x_c \cr y_c \cr z_c \cr w_c \cr \end{bmatrix} = \begin{bmatrix} n \above 1pt r & 0 & 0 & 0 \cr 0 & n \above 1pt t & 0 & 0 \cr 0 & 0 & -(f+n) \above 1pt f-n & -2fn \above 1pt f-n \cr 0 & 0 & -1 & 0 \cr \end{bmatrix} \bullet \begin{bmatrix} x_e \cr y_e \cr z_e \cr w_e(=1) \cr \end{bmatrix} $`
`$P_c = Persp(r,t,n,f) \bullet P_e$`
V:
`$$l=-r$$` `$$b=-t$$` `$$n/t = 1/\tan(fov/2)$$`(Vertical) field-of-view (fov)
V:
`$$l=-r$$` `$$b=-t$$` `$$n/t = 1/\tan(fov/2)$$` `$$n/r = 1/\tan(hfov/2)$$`
`$\begin{bmatrix} x_c \cr y_c \cr z_c \cr w_c \cr \end{bmatrix} = \begin{bmatrix} 1 \above 1pt \tan (hfov/2) & 0 & 0 & 0 \cr 0 & 1 \above 1pt \tan (fov/2) & 0 & 0 \cr 0 & 0 & -(f+n) \above 1pt f-n & -2fn \above 1pt f-n \cr 0 & 0 & -1 & 0 \cr \end{bmatrix} \bullet \begin{bmatrix} x_e \cr y_e \cr z_e \cr w_e(=1) \cr \end{bmatrix} $`
`$P_c = Persp(hfov,fov,n,f) \bullet P_e$`
V:
`$$l=-r$$` `$$b=-t$$` `$$aspectRatio=screenWidth/screenHeight$$` `$$1/\tan(hfov/2) = 1/(\tan(fov/2) * aspectRatio)$$`
`$\begin{bmatrix} x_c \cr y_c \cr z_c \cr w_c \cr \end{bmatrix} = \begin{bmatrix} 1 \above 1pt \tan (fov/2) * aspectRatio & 0 & 0 & 0 \cr 0 & 1 \above 1pt \tan (fov/2) & 0 & 0 \cr 0 & 0 & -(f+n) \above 1pt f-n & -2fn \above 1pt f-n \cr 0 & 0 & -1 & 0 \cr \end{bmatrix} \bullet \begin{bmatrix} x_e \cr y_e \cr z_e \cr w_e(=1) \cr \end{bmatrix} $`
`$P_c = Persp(fov,aspectRatio,n,f) \bullet P_e$`
V:
Vertical field-of-view (fov)V:
Adapted from [perspective](https://p5js.org/reference/#/p5/perspective)V:
Example code
var sketch = function( p ) {
p.setup = function() {
p.createCanvas(600, 600, p.WEBGL);
var fov = 60 / 180 * p.PI;
var cameraZ = p.height / 2.0 / p.tan(fov / 2.0);
// define a perspective matrix projection
p.perspective(60 / 180 * p.PI, p.width / p.height, cameraZ * 0.1, cameraZ * 10);
};
p.draw = function() {
p.background(100);
p.orbitControl(); // interactively modifies the view matrix with the mouse
p.strokeWeight(2);
p.stroke(0, 255, 0);
p.fill(255, 0, 255, 125);
for (var i = -1; i < 2; i++) {
for (var j = -2; j < 3; j++) {
p.push(); // saves current matrix transform (perspective * view)
p.translate(i * 160, 0, j * 160); // same as: perspective * view * translate
p.box(80, 80, 80);
p.pop(); // restores the top of the matrix stack: perspective * view
}
}
};
};
H:
- Math primer for graphics and game development
- Proscene: A feature-rich framework for interactive environments
- Processing 2d transformations tutorial
- OpenGL projection matrix
- The Perspective and Orthographic Projection Matrix
H:
A matrix $$M = \begin{bmatrix} m_{11} & m_{12} & m_{13} \cr m_{21} & m_{22} & m_{33} \cr m_{31} & m_{32} & m_{33} \cr \end{bmatrix}$$
is orthogonal iff:
This is equivalent to:
V:
Let
$$r_{1} = \begin{bmatrix} m_{11} & m_{12} & m_{13} \end{bmatrix}$$
$$r_{2} = \begin{bmatrix} m_{21} & m_{22} & m_{23} \end{bmatrix}$$
$$r_{3} = \begin{bmatrix} m_{31} & m_{32} & m_{33} \end{bmatrix}$$
then
$$r_{1} \cdot r_{1} = r_{2} \cdot r_{2} = r_{3} \cdot r_{3} = 1 $$
$$r_{i} \cdot r_{j} = 0\ \ i=1,2,3 \ \ j=1,2,3 \ \ i\ne j$$
V:
We can conclude that:
- Each row of the matrix must be a unit vector
- The rows of the matrix must be mutually perpendicular
- Vectors
$r_{1}, \,r_{2}, \,r_{3}$
are orthonormals
Note 1: that
$r_1$ ,$r_2$ and$r_3$ form a non-canonical basis
Note 2: that a rotation matrix is always orthogonal
N:
- Orthogonality is used in both: euler angles (composition) and rodrigues formula
V:
Suppose $u$ is part of a non-canonical basis $x', y', z'$V:
`$ R_y(\lambda) * R_x(\alpha) = \begin{bmatrix} u_{x'1} & u_{x'2} & u_{x'3} & 0 \cr u_{y'1} & u_{y'2} & u_{y'3} & 0 \cr u_{z'1} & u_{z'2} & u_{z'3} & 0 \cr 0 & 0 & 0 & 1 \cr \end{bmatrix} $`
where
`$u_{z'}=u$`
`$u_{x'}$` is _any_ orthogonal vector to `$u_{z'}$`
`$u_{y'} = u \times u_{x'}$`
</ul>
N:
missing:
- Affine transformations: Rotation: use orthogonality to compute R_y(\lambda) * R_x(\alpha)
- Affine transformations: Rotation: Quaternions magic
- Affine transformations: Rotation: Rodrigues' rotation formula