# Rotating image based on the direction of a line

• 08-06-2010, 09:10 AM
YellowPainting
Rotating image based on the direction of a line
Hello,
My question really has more to do with math than Java; although, I'm trying to rotate a buffered image using rotate(double theta) from Graphics2D based on the direction of point A to point B.
[Graphics2D (Java 2 Platform SE v1.4.2)

Could someone provide the equation? Also, if there's a better way of doing this, please do tell.

Thanks.
• 08-06-2010, 09:16 AM
JosAH
You have to define the phrase "based on the direction of point A to point B" a bit better.

kind regards,

Jos
• 08-06-2010, 09:24 AM
YellowPainting
Quote:

Originally Posted by JosAH
You have to define the phrase "based on the direction of point A to point B" a bit better.

kind regards,

Jos

I created an image to illustrate what I want to do; hopefully it'll help. The box represents the image. I would like the south part of the box to be parallel with the line.

http://img831.imageshack.us/img831/7606/examplehp.png
• 08-06-2010, 09:27 AM
JosAH
Quote:

Originally Posted by YellowPainting
I created an image to illustrate what I want to do; hopefully it'll help. The box represents the image. I would like the south part of the box to be parallel with the line.

http://img831.imageshack.us/img831/7606/examplehp.png

Understood; now you have to define the centre of your rotation. The angle of the rotation is defined by the slope of the line.

kind regards,

Jos
• 08-06-2010, 09:32 AM
YellowPainting
Quote:

Originally Posted by JosAH
Understood; now you have to define the centre of your rotation. The angle of the rotation is defined by the slope of the line.

kind regards,

Jos

Thanks, helped a lot.