2015-03-02 08:56:44 +01:00
|
|
|
---
|
|
|
|
|
layout: math
|
|
|
|
|
title: Environment
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Affine Transforms & Vector Math
|
|
|
|
|
|
2015-03-03 09:23:39 +01:00
|
|
|
class Transformable {
|
|
|
|
|
|
|
|
|
|
// attaributes
|
|
|
|
|
PVector _position;
|
|
|
|
|
float _rotation;
|
|
|
|
|
float _scale;
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
public void display() {
|
|
|
|
|
pushMatrix();
|
|
|
|
|
translate(_position.x, _position.y);
|
|
|
|
|
rotate(_rotation);
|
|
|
|
|
scale(_scale);
|
|
|
|
|
draw_shape();
|
|
|
|
|
popMatrix();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
What is a geometry / shape?
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
What types of (2D / 3D) transformations can we apply to geometries / shapes?
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2015-03-02 08:56:44 +01:00
|
|
|
<!-- ASCIImath -->
|
|
|
|
|
|
2015-03-03 09:23:39 +01:00
|
|
|
What is a matrix Matrix?
|
|
|
|
|
|
|
|
|
|
$
|
|
|
|
|
[[a, b, c], [d, e, f], [g, h, i]]
|
|
|
|
|
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Matrix [3 x 3] multiplication with a Vector [1 x 3]
|
|
|
|
|
|
2015-03-02 08:56:44 +01:00
|
|
|
$
|
|
|
|
|
[[a, b, c], [d, e, f], [g, h, i]] [[x], [y], [z]] = [[ax + by + cz], [dx + ey + fz], [gx + hy + iz]]
|
|
|
|
|
$
|
|
|
|
|
|
2015-03-03 09:23:39 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
|
|
What types of geometrical transformations (vertices transformation) can we perform using a Matrix?
|
|
|
|
|
|
2015-03-02 08:56:44 +01:00
|
|
|
|
|
|
|
|
Translation
|
2015-03-03 09:23:39 +01:00
|
|
|
|
2015-03-02 08:56:44 +01:00
|
|
|
$
|
|
|
|
|
[[1, 0, tx], [0, 1, ty], [0, 0, 1]] [[x], [y], [1]] = [[dot x], [dot y], [1]]
|
|
|
|
|
$
|
|
|
|
|
|
|
|
|
|
Scaling
|
2015-03-03 09:23:39 +01:00
|
|
|
|
2015-03-02 08:56:44 +01:00
|
|
|
$
|
|
|
|
|
[[sx, 0, 0], [0, sy, 0], [0, 0, 1]] [[x], [y], [1]] = [[dot x], [dot y], [1]]
|
|
|
|
|
$
|
|
|
|
|
|
|
|
|
|
Rotation $theta$
|
2015-03-03 09:23:39 +01:00
|
|
|
|
2015-03-02 08:56:44 +01:00
|
|
|
$
|
|
|
|
|
[[cos theta, -sin theta, 0], [sin theta, cos theta, 0], [0, 0, 1]] [[x], [y], [1]] = [[dot x], [dot y], [1]]
|
|
|
|
|
$
|
|
|
|
|
|
|
|
|
|
Shearing
|
2015-03-03 09:23:39 +01:00
|
|
|
|
2015-03-02 08:56:44 +01:00
|
|
|
$
|
|
|
|
|
[[1, shx, 0], [shy, 1, 0], [0, 0, 1]] [[x], [y], [1]] = [[dot x], [dot y], [1]]
|
|
|
|
|
$
|
|
|
|
|
|
2015-03-03 09:23:39 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
|
|
What is an Affine Transform?
|
|
|
|
|
|
|
|
|
|
Affine Transform Matrix comprises a Translation, Scaling, Rotation and Shearing
|
|
|
|
|
|
2015-03-02 08:56:44 +01:00
|
|
|
$
|
|
|
|
|
[[sx * cos theta, -sin theta * shx, tx], [sin theta * shy, sy * cos theta, ty], [0, 0, 1]] [[x], [y], [1]] = [[dot x], [dot y], [1]]
|
|
|
|
|
$
|
|
|
|
|
|
2015-03-03 09:23:39 +01:00
|
|
|
Yes, but what other types of transformations exists?
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
2015-03-02 08:56:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|