I have a section of map I can rotate, after rotating the coordinates I offset them so the top-left co-ordinate is (0,0). This works fine and I can add additional overlays to the map by performing the same rotation offset combination.
rotate(x) -> offset1
The problem is if I try and perform a second rotation i.e.
rotate(x) -> offset1 -> rotate(y) -> offset2
Is it possible to combine the two rotations and offsets into a single rotate offset combination and get the same result?
rotate(x+y) -> offset3
where offset3 = offset1 + offset2
This is so I can add overlays in the correct position regardless of how many rotation/offsets there have been. Id like to store a single value for the rotation and offset and not have a stack of previous operations.
Aside from removing the previous rotate/offset entirely before performing the new operations i.e. NOT
-offset1 -> rotate(-x) - > rotate(y) -> offset2
Thanks
Ben
You want transformation matrices. Use this matrix to apply a translation of (tx,ty) for a 2D-vector (x,y):
And this matrix for a rotation by theta:
Multiple translations and rotations can be combined by simply multiplying the matrices. (The order is important.)