How does Affine Transform really work in Java?

Simon Langhoff picture Simon Langhoff · Apr 14, 2011 · Viewed 15.1k times · Source

I have been using Affine Transform to rotate a String in my java project, and I am not an experienced programmer yet, so it has taking me a long time to do a seemingly small task.. To rotate a string.

Now I have finally gotten it to work more or less as I had hoped, except it is not as precisely done as I want... yet.

Since it took a lot of trial and error and reading the description of the affine transform I am still not quite sure what it really does. What I think I know at the moment, is that I take a string, and define the center of the string (or the point which I want to rotate around), but where does matrices come into this? (Apparently I do not know that hehe)

Could anyone try and explain to me how affine transform works, in other words than the java doc? Maybe it can help me tweak my implementation and also, I just would really like to know :)

Thanks in advance.

Answer

Michał Šrajer picture Michał Šrajer · Apr 15, 2011

To understand what is affine transform and how it works see the wikipedia article.

In general, it is a linear transformation (like scaling or reflecting) which can be implemented as a multiplication by specific matrix, and then followed by translation (moving) which is done by adding a vector. So to calculate for each pixel [x,y] its new location you need to multiply it by specific matrix (do the linear transform) and then add then add a specific vector (do the translation).