# Affine Transformation

Non-technically, Affine Transformations are translations, dilations/expansions/contractions, rotations, reflections, shears and combinations thereof. (Note that this list is hyper-complete - some of the items can be created by composing some of the others. For example, translations and rotations can always be obtained by a pair of reflections.)

This works in any Euclidean space, but most people only work in 2D, and a few in 3D. There are people who actually do real work (for which read commercially applicable) in 9D spaces.

In 2D all possible affine transformations are given by the simple equation

``` xnew = a*x + c*y + e
ynew = b*x + d*y + f
```

Slightly more specifically, the building blocks of AffineTransformations are:

• translation (sliding every point left, right, up, down, in out, etc.,' by the same amount)
• rotation (rotating every point around some given fixed point by the same angle)
• linear stretching (e.g., multiplying the x coordinate of every point by some constant k while leaving the y coordinate alone)
• shearing (e.g., leaving the y coordinate alone while adding to the x coordinate some constant s times the y coordinate)

An affine transformation of an ellipse always produces an ellipse (allowing that a circle is, in geometry, a specific example of an ellipse)

More technically, given any space S with concepts of colinearity and distance, an AffineTransformation is a mapping from S to S preserving colinearity of points and ratios of distances. It can be shown that parallel lines are preserved, but angles and areas/volumes are not preserved.

By comparison, a LinearTransformation is an special kind of AffineTransformation, one that leaves the origin fixed. Translations are therefore not Linear Transformations.

As an observation, the fact that translations and rotations can each be obtained as a pair of reflections leads to the idea that a translation can be thought of as a special case of a rotation. This works if you do something technical (compact the space) and think of a translation as a rotation around a point at infinity. Basically, a very big circle locally looks like a line, and as the circle gets bigger so the approximation gets better. With care you can talk about a circle whose centre is at infinity, and that's the same as a line. The detail needs considerable attention to avoid paradoxes and inconsistencies.

As an example of why it's useful, interesting and potentially important ...

The HolyGrail of ImageRecognition? systems is "AffineTransformation-independence", so a shape rates the same regardless of how you rotate it, or twist the camera's view of it.

In particular, if you look straight down at some object on a table (with a camera), any number of steps of turning the object clockwise or counterclockwise and pushing the object elsewhere on the table can be represented by a single AffineTransformation from the start position to the end position.

If the current image from that camera is (sufficiently close to) an AffineTransformation of the original training image of a screwdriver, we can be sure there is now a screwdriver on the table. If the current image is not anywhere close to an AffineTransformation of a screwdriver, then whatever is on the table is not a screwdriver.

In fact, changing the camera's view does not generally give an affine transformation because ratios of distances within a line get changed, but while that's literally true, within certain limits it's close enough.

An AffineTransformation in 2D transforms one 2D picture into another 2D picture. Any combination of any number of rotation, linear stretching, shearing, and translation steps results in a single AffineTransformation that can be represented by 6 numbers. Some kinds of transformations are not AffineTransformations, and so cannot be generated no matter how many translations, rotations, shears, or linear stretches are combined.

If you pick any 3 points in the original image (as long as they are not all on the same line) and specify 3 corresponding points in the final image, you can find the appropriate AffineTransformation and therefore find out where any point in the original image falls onto the final image. (In other words, draw a rectangle around the original image, and pick the top-left, bottom-left, and bottom-right points. Find the corresponding 3 points in the final image. Extrapolate the position of the top-right point to make a parallelogram - often not a rectangle - and then you can draw a grid to interpolate every other point).