<p>An Affine Transform is a Linear Transform + a Translation Vector.</p>

<p>$$
\begin{bmatrix}x'&amp; y'\end{bmatrix}
=
\begin{bmatrix}x&amp; y\end{bmatrix}
\cdot
\begin{bmatrix}a&amp; b \\ c&amp;d\end{bmatrix}
+
\begin{bmatrix}e&amp; f\end{bmatrix}
$$</p>

<p>It can be applied to individual points or to lines or even Bezier curves. For lines, it preserves the property that parallel lines remain parallel. For Bezier curves, it preserves the convex-hull property of the control points.</p>

<p>Multiplied-out, it produces 2 equations for yielding a "transformed" coordinate pair $(x', y')$ from the original pair $(x, y)$ and a list of constants $(a, b, c, d, e, f)$.
$$
    x' =  a\cdot x + c\cdot y + e \\
    y' =  b\cdot x + d\cdot y + f
$$</p>

<p>Conveniently, the Linear transform and the Translation vector can be put together into a 3D matrix which can operate over 2D homogeneous coordinates.</p>

<p>$$
\begin{bmatrix}x'&amp; y'&amp;1\end{bmatrix}
=
\begin{bmatrix}x&amp; y&amp;1\end{bmatrix}
\cdot
\begin{bmatrix}a&amp; b &amp;0\\ c&amp;d&amp;0 \\ e&amp;f&amp;1\end{bmatrix}
$$</p>

<p>Which yields the same 2 equations above.</p>

<p><em>Very conveniently</em>, the matrices themselves can be multiplied together to produce a third matrix (of constants) which performs the same transformation as the original 2 would perform in sequence. Put simply, the matrix multiplications are associative.</p>

<p>$$
\begin{matrix}
\begin{bmatrix}x''&amp; y''&amp;1\end{bmatrix}
&amp; = &amp;
\left(
\begin{bmatrix}x&amp; y&amp;1\end{bmatrix}
\cdot
\begin{bmatrix}a&amp; b &amp;0\\ c&amp;d&amp;0 \\ e&amp;f&amp;1\end{bmatrix}\right)
\cdot
\begin{bmatrix}g&amp; h &amp;0\\ i&amp;j&amp;0 \\ k&amp;m&amp;1\end{bmatrix}
\\
&amp; = &amp;
\begin{bmatrix}a \cdot x + c \cdot y+e &amp; b \cdot x + d \cdot y+f &amp;1 \end{bmatrix}
\cdot
\begin{bmatrix}g&amp; h &amp;0\\ i&amp;j&amp;0 \\ k&amp;m&amp;1\end{bmatrix}
\\
&amp;=&amp;
\begin{bmatrix}g(a \cdot x + c \cdot y+e) + i( b \cdot x + d \cdot y+f) + k 
\\
h(a \cdot x + c \cdot y+e) + j( b \cdot x + d \cdot y+f) + m
\\1 \end{bmatrix}^T
\\
&amp;=&amp;
\begin{bmatrix}x&amp; y&amp;1\end{bmatrix} \cdot
\left(
\begin{bmatrix}a&amp; b &amp;0\\ c&amp;d&amp;0 \\ e&amp;f&amp;1\end{bmatrix}
\cdot
\begin{bmatrix}g&amp; h &amp;0\\ i&amp;j&amp;0 \\ k&amp;m&amp;1\end{bmatrix}
\right)
\\
&amp;=&amp;
\begin{bmatrix}x&amp; y&amp;1\end{bmatrix} \cdot
\begin{bmatrix}ag+bi&amp; ah+bj &amp;0\\ cg+di&amp;ch+dj&amp;0 \\ eg+fi+k&amp;eh+fj+m&amp;1\end{bmatrix}
\end{matrix}
$$</p>

<p>Alternatively you can consider a few basic transform types and compose any more complex transform by combining these (multiplying them together).</p>

<p>Identity transform</p>

<p><a href="https://i.sstatic.net/icgx0.png" rel="noreferrer"><img src="https://i.sstatic.net/icgx0.png" alt="identity transform"></a></p>

<p>$$\begin{bmatrix}
    1 &amp; 0 &amp; 0 \\
    0 &amp; 1 &amp; 0 \\
    0 &amp; 0 &amp; 1
\end{bmatrix}$$</p>

<p>Scaling</p>

<p><a href="https://i.sstatic.net/YVdBw.png" rel="noreferrer"><img src="https://i.sstatic.net/YVdBw.png" alt="scaling"></a></p>

<p>$$\begin{bmatrix}
    S_x &amp; 0 &amp; 0 \\
    0  &amp; S_y &amp; 0 \\
    0 &amp; 0 &amp; 1 \\
\end{bmatrix}$$</p>

<p>*Note: a reflection can be performed with scaling parameters $(S_x, S_y) = (-1,1)$ or $(1,-1)$.</p>

<p>Translation</p>

<p><a href="https://i.sstatic.net/kH8uS.png" rel="noreferrer"><img src="https://i.sstatic.net/kH8uS.png" alt="translation"></a></p>

<p>$$\begin{bmatrix}
    1 &amp; 0 &amp; 0 \\
    0 &amp; 1 &amp; 0 \\
    T_x &amp; T_y &amp; 1
\end{bmatrix}$$</p>

<p>Skew x by y</p>

<p><a href="https://i.sstatic.net/gyZCZ.png" rel="noreferrer"><img src="https://i.sstatic.net/gyZCZ.png" alt="skew x by y"></a></p>

<p>$$\begin{bmatrix}
    1  &amp; Q_x &amp; 0 \\
    0 &amp; 1 &amp; 0 \\
    0 &amp; 0 &amp; 1
\end{bmatrix}$$</p>

<p>Skew y by x</p>

<p><a href="https://i.sstatic.net/7zEWw.png" rel="noreferrer"><img src="https://i.sstatic.net/7zEWw.png" alt="skew y by x"></a></p>

<p>$$\begin{bmatrix}
    1  &amp; 0 &amp; 0 \\
    Q_y &amp; 1 &amp; 0 \\
    0 &amp; 0 &amp; 1
\end{bmatrix}$$</p>

<p>Rotation</p>

<p><a href="https://i.sstatic.net/Ltr0w.png" rel="noreferrer"><img src="https://i.sstatic.net/Ltr0w.png" alt="rotation"></a></p>

<p>$$\begin{bmatrix}
    \cos\theta &amp; -sin\theta &amp; 0\\
    \sin\theta &amp; \cos\theta &amp; 0\\
    0  &amp;  0 &amp;  1
\end{bmatrix}
$$</p>

<p>[Note I've shown the form of Matrix here which accepts a row vector on the <em>left</em>. The transpose of these matrices will work with a column vector on the right.]</p>

<p>A matrix composed purely from scaling, rotation, and translation can be <a href="https://stackoverflow.com/a/11942636/733077">decomposed back into these three components</a>.</p>

CC BY-SA 3.0
2015-09-01T06:08:21.133Z
Great answer. You might want to add that one way to think about affine transforms is that they keep parallel lines parallel. Hence, scaling, rotation, translation, shear and combinations, count as affine. Perspective projection is an example of a non-affine transformation.
ap_
CC BY-SA 3.0
2015-09-01T07:54:03.350Z
You could add some pictures. If you wont I will :P Also might be good to mention order in matrix and row/column orientation is arbitrary. And that rotations in 3d are not comutative.
joojaa
CC BY-SA 3.0
2015-09-02T02:45:00.567Z
@joojaa I made pictures! [postscript sources](https://groups.google.com/d/topic/comp.lang.postscript/m2QqV4QFFaM/discussion)
luser droog
CC BY-SA 3.0
2016-10-02T04:29:48.287Z
It might also be worth mentioning that rigid body transforms are a subset of affine transforms, and affine transforms are a subset of perspective transforms.
user1118321
CC BY-SA 4.0
2019-05-23T01:32:17.080Z
I keep re-reading this every once in while and I can't quite tell, but I might have the skew transforms described wrongly. Skews are confusing. If anyone sees this and want to have a go at editing, please help clarify that part!
luser droog
CC BY-SA 3.0
2015-09-01T00:39:04.890Z
2016-10-03T18:00:25.803Z
2017-05-23T12:39:19.850Z
luser droog
<p>What are Affine Tranformations? Do they apply just to points or to other shapes as well? What does it mean that they can be "composed"?</p>

<transformations><affine-transformations>
What are Affine Transformations?
luser droog
# What are Affine Transformations?

(Asked by: username_0 on 2015-09-01)

What are Affine Tranformations? Do they apply just to points or to other shapes as well? What does it mean that they can be "composed"?

**Tags:** transformations, affine-transformations


---

## 1 answers

### Answer by username_0 on 2015-09-01. Score: 26 | Accepted answer

An Affine Transform is a Linear Transform + a Translation Vector.

$$
\begin{bmatrix}x'& y'\end{bmatrix}
=
\begin{bmatrix}x& y\end{bmatrix}
\cdot
\begin{bmatrix}a& b \\ c&d\end{bmatrix}
+
\begin{bmatrix}e& f\end{bmatrix}
$$

It can be applied to individual points or to lines or even Bezier curves. For lines, it preserves the property that parallel lines remain parallel. For Bezier curves, it preserves the convex-hull property of the control points.

Multiplied-out, it produces 2 equations for yielding a "transformed" coordinate pair $(x', y')$ from the original pair $(x, y)$ and a list of constants $(a, b, c, d, e, f)$.
$$
x' = a\cdot x + c\cdot y + e \\
y' = b\cdot x + d\cdot y + f
$$

Conveniently, the Linear transform and the Translation vector can be put together into a 3D matrix which can operate over 2D homogeneous coordinates.

$$
\begin{bmatrix}x'& y'&1\end{bmatrix}
=
\begin{bmatrix}x& y&1\end{bmatrix}
\cdot
\begin{bmatrix}a& b &0\\ c&d&0 \\ e&f&1\end{bmatrix}
$$

Which yields the same 2 equations above.

*Very conveniently*, the matrices themselves can be multiplied together to produce a third matrix (of constants) which performs the same transformation as the original 2 would perform in sequence. Put simply, the matrix multiplications are associative.

$$
\begin{matrix}
\begin{bmatrix}x''& y''&1\end{bmatrix}
& = &
\left(
\begin{bmatrix}x& y&1\end{bmatrix}
\cdot
\begin{bmatrix}a& b &0\\ c&d&0 \\ e&f&1\end{bmatrix}\right)
\cdot
\begin{bmatrix}g& h &0\\ i&j&0 \\ k&m&1\end{bmatrix}
\\
& = &
\begin{bmatrix}a \cdot x + c \cdot y+e & b \cdot x + d \cdot y+f &1 \end{bmatrix}
\cdot
\begin{bmatrix}g& h &0\\ i&j&0 \\ k&m&1\end{bmatrix}
\\
&=&
\begin{bmatrix}g(a \cdot x + c \cdot y+e) + i( b \cdot x + d \cdot y+f) + k
\\
h(a \cdot x + c \cdot y+e) + j( b \cdot x + d \cdot y+f) + m
\\1 \end{bmatrix}^T
\\
&=&
\begin{bmatrix}x& y&1\end{bmatrix} \cdot
\left(
\begin{bmatrix}a& b &0\\ c&d&0 \\ e&f&1\end{bmatrix}
\cdot
\begin{bmatrix}g& h &0\\ i&j&0 \\ k&m&1\end{bmatrix}
\right)
\\
&=&
\begin{bmatrix}x& y&1\end{bmatrix} \cdot
\begin{bmatrix}ag+bi& ah+bj &0\\ cg+di&ch+dj&0 \\ eg+fi+k&eh+fj+m&1\end{bmatrix}
\end{matrix}
$$

Alternatively you can consider a few basic transform types and compose any more complex transform by combining these (multiplying them together).

Identity transform

[![identity transform](https://i.sstatic.net/icgx0.png)](https://i.sstatic.net/icgx0.png)

$$\begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{bmatrix}$$

Scaling

[![scaling](https://i.sstatic.net/YVdBw.png)](https://i.sstatic.net/YVdBw.png)

$$\begin{bmatrix}
S\_x & 0 & 0 \\
0 & S\_y & 0 \\
0 & 0 & 1 \\
\end{bmatrix}$$

\*Note: a reflection can be performed with scaling parameters $(S\_x, S\_y) = (-1,1)$ or $(1,-1)$.

Translation

[![translation](https://i.sstatic.net/kH8uS.png)](https://i.sstatic.net/kH8uS.png)

$$\begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
T\_x & T\_y & 1
\end{bmatrix}$$

Skew x by y

[![skew x by y](https://i.sstatic.net/gyZCZ.png)](https://i.sstatic.net/gyZCZ.png)

$$\begin{bmatrix}
1 & Q\_x & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{bmatrix}$$

Skew y by x

[![skew y by x](https://i.sstatic.net/7zEWw.png)](https://i.sstatic.net/7zEWw.png)

$$\begin{bmatrix}
1 & 0 & 0 \\
Q\_y & 1 & 0 \\
0 & 0 & 1
\end{bmatrix}$$

Rotation

[![rotation](https://i.sstatic.net/Ltr0w.png)](https://i.sstatic.net/Ltr0w.png)

$$\begin{bmatrix}
\cos\theta & -sin\theta & 0\\
\sin\theta & \cos\theta & 0\\
0 & 0 & 1
\end{bmatrix}
$$

[Note I've shown the form of Matrix here which accepts a row vector on the *left*. The transpose of these matrices will work with a column vector on the right.]

A matrix composed purely from scaling, rotation, and translation can be [decomposed back into these three components](https://stackoverflow.com/a/11942636/733077).

> **Comments:**
> **username_1**: Great answer. You might want to add that one way to think about affine transforms is that they keep parallel lines parallel. Hence, scaling, rotation, translation, shear and combinations, count as affine. Perspective projection is an example of a non-affine transformation.  
> **username_2**: You could add some pictures. If you wont I will :P Also might be good to mention order in matrix and row/column orientation is arbitrary. And that rotations in 3d are not comutative.  
> **username_0**: @username_2 I made pictures! [postscript sources](https://groups.google.com/d/topic/comp.lang.postscript/m2QqV4QFFaM/discussion)  
> **username_3**: It might also be worth mentioning that rigid body transforms are a subset of affine transforms, and affine transforms are a subset of perspective transforms.  
> **username_0**: I keep re-reading this every once in while and I can't quite tell, but I might have the skew transforms described wrongly. Skews are confusing. If anyone sees this and want to have a go at editing, please help clarify that part!  

---

