2
votes

I have 2 images which user selects matching points on both images I calculate the rotation angle needed, to align the images

The rotation angle id defined in this coordinate system

           -90
      -180  |    0
        ---------
      180   |    0
            90

My graphics view is defined by this coordinate system

           270
       180--|--0
           90

The rotation angle is correct How do I determine which way to rotate?

Example if X & Y are points on images The rotation angle is -110 either way defined by the coordinate system

           x  |
              |
          -------y-
              |
              |

How do I create an if statement to determine which way to rotate

note: if rotation angle is between -90 & 90 then by applying the rotation by the original value WORKS, But if the value is not between those value it does not rotate properly

From example above if I'm rotating x -> y (x needs to rotate positive) but if y -> x (y needs to rotate negative) BUT the original value is -110 either way so I'm guessing I can't use the rotation angle as a parameter to determine which way to rotate

It think it is simple but for some reason I can't get my head around it

2

2 Answers

2
votes

Your coordinate systems are identical! -90deg == 270deg (in this context)

The transform you need to apply is:

From wikipedia

where x and y are your original coordinates, and x' y' are your new coordinates. The rotation angle is theta

EDIT:

I should add this performs rotation about the origin. If you want to rotate about another point, you need to translate your image first, until the origin is where you require it to be

0
votes

If I understand correctly, x and y are two angles defined by the points X and Y. In you're example, x == -110, and y == 0.

Then to rotate x->y, simply rotate by the angle y-x (=110), and to rotate y->x, rotate by an angle x-y (=-110).