# Affine transformation

(Redirected from Affine map)
An image of a fern-like fractal that exhibits affine self-similarity. Each of the leaves of the fern is related to each other leaf by an affine transformation. For instance, the red leaf can be transformed into both the dark blue leaf and the light blue leaf by a combination of reflection, rotation, scaling, and translation.

In geometry, an affine transformation, affine map[1] or an affinity (from the Latin, affinis, "connected with") is a function between affine spaces which preserves points, straight lines and planes. Also, sets of parallel lines remain parallel after an affine transformation. An affine transformation does not necessarily preserve angles between lines or distances between points, though it does preserve ratios of distances between points lying on a straight line.

Examples of affine transformations include translation, scaling, homothety, similarity transformation, reflection, rotation, shear mapping, and compositions of them in any combination and sequence.

If ${\displaystyle X}$ and ${\displaystyle Y}$ are affine spaces, then every affine transformation ${\displaystyle f\colon X\to Y}$ is of the form ${\displaystyle x\mapsto Mx+b}$, where ${\displaystyle M}$ is a linear transformation on the space ${\displaystyle X}$, ${\displaystyle x}$ is a vector in ${\displaystyle X}$, and ${\displaystyle b}$ is a vector in ${\displaystyle Y}$. Unlike a purely linear transformation, an affine map need not preserve the zero point in a linear space. Thus, every linear transformation is affine, but not every affine transformation is linear.

All Euclidean spaces are affine, but there are affine spaces that are non-Euclidean. In affine coordinates, which include Cartesian coordinates in Euclidean spaces, each output coordinate of an affine map is a linear function (in the sense of calculus) of all input coordinates. Another way to deal with affine transformations systematically is to select a point as the origin; then, any affine transformation is equivalent to a linear transformation (of position vectors) followed by a translation.

## Mathematical definition

An affine map[1] ${\displaystyle f\colon {\mathcal {A}}\to {\mathcal {B}}}$  between two affine spaces is a map on the points that acts linearly on the vectors (that is, the vectors between points of the space). In symbols, ${\displaystyle f}$  determines a linear transformation ${\displaystyle \varphi }$  such that, for any pair of points ${\displaystyle P,Q\in {\mathcal {A}}}$ :

${\displaystyle {\overrightarrow {f(P)~f(Q)}}=\varphi ({\overrightarrow {PQ}})}$

or

${\displaystyle f(Q)-f(P)=\varphi (Q-P)}$ .

We can interpret this definition in a few other ways, as follows.

If an origin ${\displaystyle O\in {\mathcal {A}}}$  is chosen, and ${\displaystyle B}$  denotes its image ${\displaystyle f(O)\in {\mathcal {B}}}$ , then this means that for any vector ${\displaystyle {\vec {x}}}$ :

${\displaystyle f\colon (O+{\vec {x}})\mapsto (B+\varphi ({\vec {x}}))}$ .

If an origin ${\displaystyle O'\in {\mathcal {B}}}$  is also chosen, this can be decomposed as an affine transformation ${\displaystyle g\colon {\mathcal {A}}\to {\mathcal {B}}}$  that sends ${\displaystyle O\mapsto O'}$ , namely

${\displaystyle g\colon (O+{\vec {x}})\mapsto (O'+\varphi ({\vec {x}}))}$ ,

followed by the translation by a vector ${\displaystyle {\vec {b}}={\overrightarrow {O'B}}}$ .

The conclusion is that, intuitively, ${\displaystyle f}$  consists of a translation and a linear map.

### Alternative definition

Given two affine spaces ${\displaystyle {\mathcal {A}}}$  and ${\displaystyle {\mathcal {B}}}$ , over the same field, a function ${\displaystyle f\colon {\mathcal {A}}\to {\mathcal {B}}}$  is an affine map if and only if for every family ${\displaystyle \{(a_{i},\lambda _{i})\}_{i\in I}}$  of weighted points in ${\displaystyle {\mathcal {A}}}$  such that

${\displaystyle \sum _{i\in I}\lambda _{i}=1}$ ,

we have[2]

${\displaystyle f\left(\sum _{i\in I}\lambda _{i}a_{i}\right)=\sum _{i\in I}\lambda _{i}f(a_{i})}$ .

In other words, ${\displaystyle f}$  preserves barycenters.

## Representation

As shown above, an affine map is the composition of two functions: a translation and a linear map. Ordinary vector algebra uses matrix multiplication to represent linear maps, and vector addition to represent translations. Formally, in the finite-dimensional case, if the linear map is represented as a multiplication by a matrix ${\displaystyle A}$  and the translation as the addition of a vector ${\displaystyle {\vec {b}}}$ , an affine map ${\displaystyle f}$  acting on a vector ${\displaystyle {\vec {x}}}$  can be represented as

${\displaystyle {\vec {y}}=f({\vec {x}})=A{\vec {x}}+{\vec {b}}.}$

### Augmented matrix

Affine transformations on the 2D plane can be performed in three dimensions. Translation is done by shearing along over the z axis, and rotation is performed around the z axis.

Using an augmented matrix and an augmented vector, it is possible to represent both the translation and the linear map using a single matrix multiplication. The technique requires that all vectors are augmented with a "1" at the end, and all matrices are augmented with an extra row of zeros at the bottom, an extra column—the translation vector—to the right, and a "1" in the lower right corner. If ${\displaystyle A}$  is a matrix,

${\displaystyle {\begin{bmatrix}{\vec {y}}\\1\end{bmatrix}}=\left[{\begin{array}{ccc|c}\,&A&&{\vec {b}}\ \\0&\ldots &0&1\end{array}}\right]{\begin{bmatrix}{\vec {x}}\\1\end{bmatrix}}}$

is equivalent to the following

${\displaystyle {\vec {y}}=A{\vec {x}}+{\vec {b}}.}$

The above-mentioned augmented matrix is called an affine transformation matrix. In the general case, when the last row vector is not restricted to be ${\displaystyle \left[{\begin{array}{ccc|c}0&\ldots &0&1\end{array}}\right]}$ , the matrix becomes a projective transformation matrix (as it can also be used to perform projective transformations).

This representation exhibits the set of all invertible affine transformations as the semidirect product of ${\displaystyle K^{n}}$  and ${\displaystyle GL(n,K)}$ . This is a group under the operation of composition of functions, called the affine group.

Ordinary matrix-vector multiplication always maps the origin to the origin, and could therefore never represent a translation, in which the origin must necessarily be mapped to some other point. By appending the additional coordinate "1" to every vector, one essentially considers the space to be mapped as a subset of a space with an additional dimension. In that space, the original space occupies the subset in which the additional coordinate is 1. Thus the origin of the original space can be found at ${\displaystyle (0,0,\dotsc ,0,1)}$ . A translation within the original space by means of a linear transformation of the higher-dimensional space is then possible (specifically, a shear transformation). The coordinates in the higher-dimensional space are an example of homogeneous coordinates. If the original space is Euclidean, the higher dimensional space is a real projective space.

The advantage of using homogeneous coordinates is that one can combine any number of affine transformations into one by multiplying the respective matrices. This property is used extensively in computer graphics, computer vision and robotics.

#### Example augmented matrix

If the vectors ${\displaystyle {\vec {x}}_{1},\dotsc ,{\vec {x}}_{n+1}}$  are a basis of the domain's projective vector space and if ${\displaystyle {\vec {y}}_{1},\dotsc ,{\vec {y}}_{n+1}}$  are the corresponding vectors in the codomain vector space then the augmented matrix ${\displaystyle M}$  that achieves this affine transformation

${\displaystyle \left[{\begin{array}{c}{\vec {y}}\\1\end{array}}\right]=M\left[{\begin{array}{c}{\vec {x}}\\1\end{array}}\right]}$

is

${\displaystyle M=\left[{\begin{array}{ccc}{\vec {y}}_{1}&\ldots &{\vec {y}}_{n+1}\\1&\ldots &1\end{array}}\right]\left[{\begin{array}{ccc}{\vec {x}}_{1}&\ldots &{\vec {x}}_{n+1}\\1&\ldots &1\end{array}}\right]^{-1}}$ .

This formulation works irrespective of whether any of the domain, codomain and image vector spaces have the same number of dimensions.

For example, the affine transformation of a vector plane is uniquely determined from the knowledge of where the three vertices of a non-degenerate triangle are mapped to.

## Properties

### Properties preserved

An affine transformation preserves:

1. collinearity between points: three or more points which lie on the same line (called collinear points) continue to be collinear after the transformation.
2. parallelism: two or more lines which are parallel, continue to be parallel after the transformation.
3. convexity of sets: a convex set continues to be convex after the transformation. Moreover, the extreme points of the original set are mapped to the extreme points of the transformed set.[3]
4. ratios of lengths of parallel line segments: for distinct parallel segments defined by points ${\displaystyle p_{1}}$  and ${\displaystyle p_{2}}$ , ${\displaystyle p_{3}}$  and ${\displaystyle p_{4}}$ , the ratio of ${\displaystyle {\overrightarrow {p_{1}p_{2}}}}$  and ${\displaystyle {\overrightarrow {p_{3}p_{4}}}}$  is the same as that of ${\displaystyle {\overrightarrow {f(p_{1})f(p_{2})}}}$  and ${\displaystyle {\overrightarrow {f(p_{3})f(p_{4})}}}$ .
5. barycenters of weighted collections of points.

### Groups

An affine transformation is invertible if and only if ${\displaystyle A}$  is invertible. In the matrix representation, the inverse is:

${\displaystyle \left[{\begin{array}{ccc|c}&A^{-1}&&-A^{-1}{\vec {b}}\ \\0&\ldots &0&1\end{array}}\right]}$

The invertible affine transformations (of an affine space onto itself) form the affine group, which has the general linear group of degree ${\displaystyle n}$  as subgroup and is itself a subgroup of the general linear group of degree ${\displaystyle n+1}$ .

The similarity transformations form the subgroup where ${\displaystyle A}$  is a scalar times an orthogonal matrix. For example, if the affine transformation acts on the plane and if the determinant of ${\displaystyle A}$  is 1 or −1 then the transformation is an equiareal mapping. Such transformations form a subgroup called the equi-affine group.[4] A transformation that is both equi-affine and a similarity is an isometry of the plane taken with Euclidean distance.

Each of these groups has a subgroup of orientation-preserving or positive affine transformations: those where the determinant of ${\displaystyle A}$  is positive. In the last case this is in 3D the group of rigid body motions (proper rotations and pure translations).

If there is a fixed point, we can take that as the origin, and the affine transformation reduces to a linear transformation. This may make it easier to classify and understand the transformation. For example, describing a transformation as a rotation by a certain angle with respect to a certain axis may give a clearer idea of the overall behavior of the transformation than describing it as a combination of a translation and a rotation. However, this depends on application and context.

## Image transformation

In their applications to digital image processing, the affine transformations are analogous to printing on a sheet of rubber and stretching the sheet's edges parallel to the plane. This transform relocates pixels requiring intensity interpolation to approximate the value of moved pixels, bicubic interpolation is the standard for image transformations in image processing applications. Affine transformations scale, rotate, translate, mirror and shear images as shown in the following examples:[5]

Transformation name Affine matrix Example
Identity (transform to original image) ${\displaystyle {\begin{bmatrix}1&0&0\\0&1&0\\0&0&1\end{bmatrix}}}$
Reflection ${\displaystyle {\begin{bmatrix}-1&0&0\\0&1&0\\0&0&1\end{bmatrix}}}$
Scale ${\displaystyle {\begin{bmatrix}c_{x}=2&0&0\\0&c_{y}=1&0\\0&0&1\end{bmatrix}}}$
Rotate ${\displaystyle {\begin{bmatrix}\cos(\theta )&-\sin(\theta )&0\\\sin(\theta )&\cos(\theta )&0\\0&0&1\end{bmatrix}}}$    where θ = π/6 =30°
Shear ${\displaystyle {\begin{bmatrix}1&c_{x}=0.5&0\\c_{y}=0&1&0\\0&0&1\end{bmatrix}}}$

The affine transforms are applicable to the registration process where two or more images are aligned (registered). An example of image registration is the generation of panoramic images that are the product of multiple images stitched together.

### Affine warping

The affine transform preserves parallel lines. However, the stretching and shearing transformations warp shapes, as the following example shows:

This is an example of image warping. However, the affine transformations do not facilitate projection onto a curved surface or radial distortions.

## In the plane

A central dilation. The triangles A1B1Z, A1C1Z, and B1C1Z get mapped to A2B2Z, A2C2Z, and B2C2Z, respectively.

Affine transformations in two real dimensions include:

• pure translations,
• scaling in a given direction, with respect to a line in another direction (not necessarily perpendicular), combined with translation that is not purely in the direction of scaling; taking "scaling" in a generalized sense it includes the cases that the scale factor is zero (projection) or negative; the latter includes reflection, and combined with translation it includes glide reflection,
• rotation combined with a homothety and a translation,
• shear mapping combined with a homothety and a translation, or
• squeeze mapping combined with a homothety and a translation.

To visualise the general affine transformation of the Euclidean plane, take labelled parallelograms ABCD and A′B′C′D′. Whatever the choices of points, there is an affine transformation T of the plane taking A to A′, and each vertex similarly. Supposing we exclude the degenerate case where ABCD has zero area, there is a unique such affine transformation T. Drawing out a whole grid of parallelograms based on ABCD, the image T(P) of any point P is determined by noting that T(A) = A′, T applied to the line segment AB is A′B′, T applied to the line segment AC is A′C′, and T respects scalar multiples of vectors based at A. [If A, E, F are collinear then the ratio length(AF)/length(AE) is equal to length(AF′)/length(AE′).] Geometrically T transforms the grid based on ABCD to that based in A′B′C′D′.

Affine transformations do not respect lengths or angles; they multiply area by a constant factor

area of A′B′C′D′ / area of ABCD.

A given T may either be direct (respect orientation), or indirect (reverse orientation), and this may be determined by its effect on signed areas (as defined, for example, by the cross product of vectors).

## Examples

### Over the real numbers

Functions ${\displaystyle f\colon \mathbb {R} \to \mathbb {R} ,\;f(x)=mx+c}$  with ${\displaystyle m}$  and ${\displaystyle c}$  constant, are commonplace affine transformations.

### Over a finite field

The following equation expresses an affine transformation in GF(28):

${\displaystyle \{a'\}=M\{a\}\oplus \{v\},}$
 where ${\displaystyle [M]}$  is the matrix and ${\displaystyle \{v\}}$  is the vector ${\displaystyle M\{a\}={\begin{bmatrix}1&0&0&0&1&1&1&1\\1&1&0&0&0&1&1&1\\1&1&1&0&0&0&1&1\\1&1&1&1&0&0&0&1\\1&1&1&1&1&0&0&0\\0&1&1&1&1&1&0&0\\0&0&1&1&1&1&1&0\\0&0&0&1&1&1&1&1\end{bmatrix}}}$  :${\displaystyle \{v\}={\begin{bmatrix}1\\1\\0\\0\\0\\1\\1\\0\end{bmatrix}}.}$

For instance, the affine transformation of the element ${\displaystyle \{a\}=y^{7}+y^{6}+y^{3}+y=\{11001010_{2}\}}$  in big-endian binary notation = ${\displaystyle \{{\text{CA}}_{16}\}}$  in big-endian hexadecimal notation, is calculated as follows:

${\displaystyle a_{0}'=a_{0}\oplus a_{4}\oplus a_{5}\oplus a_{6}\oplus a_{7}\oplus 1=0\oplus 0\oplus 0\oplus 1\oplus 1\oplus 1=1}$
${\displaystyle a_{1}'=a_{0}\oplus a_{1}\oplus a_{5}\oplus a_{6}\oplus a_{7}\oplus 1=0\oplus 1\oplus 0\oplus 1\oplus 1\oplus 1=0}$
${\displaystyle a_{2}'=a_{0}\oplus a_{1}\oplus a_{2}\oplus a_{6}\oplus a_{7}\oplus 0=0\oplus 1\oplus 0\oplus 1\oplus 1\oplus 0=1}$
${\displaystyle a_{3}'=a_{0}\oplus a_{1}\oplus a_{2}\oplus a_{3}\oplus a_{7}\oplus 0=0\oplus 1\oplus 0\oplus 1\oplus 1\oplus 0=1}$
${\displaystyle a_{4}'=a_{0}\oplus a_{1}\oplus a_{2}\oplus a_{3}\oplus a_{4}\oplus 0=0\oplus 1\oplus 0\oplus 1\oplus 0\oplus 0=0}$
${\displaystyle a_{5}'=a_{1}\oplus a_{2}\oplus a_{3}\oplus a_{4}\oplus a_{5}\oplus 1=1\oplus 0\oplus 1\oplus 0\oplus 0\oplus 1=1}$
${\displaystyle a_{6}'=a_{2}\oplus a_{3}\oplus a_{4}\oplus a_{5}\oplus a_{6}\oplus 1=0\oplus 1\oplus 0\oplus 0\oplus 1\oplus 1=1}$
${\displaystyle a_{7}'=a_{3}\oplus a_{4}\oplus a_{5}\oplus a_{6}\oplus a_{7}\oplus 0=1\oplus 0\oplus 0\oplus 1\oplus 1\oplus 0=1.}$

Thus, ${\displaystyle \{a'\}=y^{7}+y^{6}+y^{5}+y^{3}+y^{2}+1=\{11101101_{2}\}=\{{\text{ED}}_{16}\}}$ .

### In plane geometry

A simple affine transformation on the real plane

Effect of applying various 2D affine transformation matrices on a unit square. Note that the reflection matrices are special cases of the scaling matrix.

In ℝ2, the transformation shown at left is accomplished using the map given by:

${\displaystyle {\begin{bmatrix}x\\y\end{bmatrix}}\mapsto {\begin{bmatrix}0&1\\2&1\end{bmatrix}}{\begin{bmatrix}x\\y\end{bmatrix}}+{\begin{bmatrix}-100\\-100\end{bmatrix}}}$

Transforming the three corner points of the original triangle (in red) gives three new points which form the new triangle (in blue). This transformation skews and translates the original triangle.

In fact, all triangles are related to one another by affine transformations. This is also true for all parallelograms, but not for all quadrilaterals.