-1

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;
}

https://stackoverflow.com/a/12025915/5220303

halfer
  • 19,824
  • 17
  • 99
  • 186
Think Big
  • 1,021
  • 14
  • 24

1 Answers1

0

i find this formula for image 2

float degree = -(float)(Math.Atan2(pointAy - pointBy, pointAx - pointBx) * (180 / Math.PI));

Think Big
  • 1,021
  • 14
  • 24