# Is perspective transform affine? If it is, why it's impossible to perspective a square by an affine transform, given by matrix and shift vector?

I'm a bit confused. I want to program a perspective transformation and thought that it is an affine one, but seemingly it is not. As an example, I want to perspective a square into a quadrilateral (as shown below), but it seems impossible to represent such a transform as a matrix multiplication+shift:

1) What I can't understand is that by definition affine transform is the one, that preserves all the staight lines. Can you provide an example of straight line, which is not preserved in this case?

2) How do I represent perspective transforms as this one numerically?

Thank you.

• Any transformation that takes some two parallel lines into two non-parallel lines is non-affine. "Preserving straight lines" describes the projective transformations (under appropriate algebraicity conditions, perhaps -- I don't remember), while affine transformations also need to "fix the line at infinity" (i. e., preserve parallelism). Jun 7 '13 at 15:06
• @darijgrinberg Hm, interesting enough, in russian tradition only preservation of straight lines is required for a transformation to be called affine :) unlike english: en.wikipedia.org/wiki/Homography. Thanks! Jun 7 '13 at 15:14
• @Bob I've edited my answer to include the actual transformation. Jun 7 '13 at 15:33
• @darijgrinberg Sorry, I was wrong about russian tradition. Affine transforms in russian are the same as in english. It was just a wrong definition in russian Wikipedia. Jun 12 '13 at 13:19

In local coordinates, a projective transformation is given by: $$(x,y) \longmapsto \left(\frac{ax+by+c}{gx+hy+k},\frac{dx+ey+f}{gx+hy+k}\right)$$
$$T : (x,y) \longmapsto \left( \frac{12x+3y}{4y+16} , \frac{3y}{y+4} \right) .$$
• @Bob You're welcome. Please take care when using the $\arctan$ function. It has a nasty habit of biting! Jun 12 '13 at 17:29