How does Affine Transform work in Java?

I use Affine Transform to rotate String in my java project, and I'm not an experienced programmer yet, so it took me a long time to do a small task. Rotate the line.

Now I finally got the job more or less, as I hoped, but it's not as accurate as I want ... for now.

Since it required a lot of trial and error and reading the description of the affine transformation, I'm still not quite sure what it actually does. What I think I know at the moment is that I take the line and determine the center of the line (or the point I want to rotate), but where do the matrices go into this? (Apparently, I do not know what hehe)

Can someone try to explain to me how the affine transform works, in other words, than a Java document? Maybe this will help me customize my implementation, and also I just would like to know :)

Thanks in advance.

+5
source share
5 answers

To understand what an affine transformation is and how it works, see the article .

, (, ), , (), . , [x, y] , ( ), ( ).

+5

, :

  • x y, (x, y). .

  • () , - ().

  • (.. ) , , , , . /p >

, , . :

  • 2 , ( , , nit-picking;-)).
  • 2 , , ( btw).
  • , . , .
  • Btw 3D.

. .

+3
+2

, , , , :

  • (x, y) , translate(-x,-y).
  • rotate(angle) ( )
  • translate(x,y).

, (. trashgod).

, . , .

Rectangle2D r = g.getFontMetrics().getStringBounds(text, g);
g.translate(final_x, final_y);
g.rotate(-angle);
g.translate(-r.getCenterX(), -r.getCenterY());
g.drawString(text, 0, 0);

, ,

Rectangle2D r = g.getFontMetrics().getStringBounds(text, g);
AffineTransform trans = AffineTransform.getTranslateInstance(final_x, final_y);
trans.concatenate(AffineTransform.getRotateInstance(-angle));
trans.concatenate(AffineTransform.getTranslateInstance(-r.getCenterX(), -r.getCenterY()));
g.setTransform(trans);
g.drawString(text, 0, 0);
+2

Here's a purely mathematical video tutorial on how to create a transformation matrix for your needs http://www.khanacademy.org/video/linear-transformation-examples--scaling-and-reflections?topic=linear-algebra

You may have to watch previous videos to understand how and why these matrices work. In any case, this is a good resource for studying linear algebra, if you have enough patience.

+2
source

All Articles