i have two point, A and B.
i need a formula in C# for rotate this picture base two point.
A = * , B = + , . = center of image
>image 1
---------------
| * |
| . |
| + |
---------------
>after rotate
---------------
| * + |
| . |
| |
---------------
or
>image 2
---------------
| * |
| . |
| + |
---------------
>after rotate
---------------
| + * |
| . |
| |
---------------
i find a formula for rotate image 1
, but this formula not working for image 2
. this formula is:
float degree = -(float)(Math.Atan2(pointBy - pointAy, pointBx - pointAx) * (180 / Math.PI))
also i use this function for rotate a bitmap
private Bitmap RotateImage( Bitmap bmp, float angle ) {
Bitmap rotatedImage = new Bitmap( bmp.Width, bmp.Height );
using ( Graphics g = Graphics.FromImage( rotatedImage ) ) {
g.TranslateTransform( bmp.Width / 2, bmp.Height / 2 ); //set the rotation point as the center into the matrix
g.RotateTransform( angle ); //rotate
g.TranslateTransform( -bmp.Width / 2, -bmp.Height / 2 ); //restore rotation point into the matrix
g.DrawImage( bmp, new Point( 0, 0 ) ); //draw the image on the new bitmap
}
return rotatedImage;
}