Jon
Jon

Reputation: 678

Rotating offset coordinates

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

Upvotes: 1

Views: 1443

Answers (2)

Ishtar
Ishtar

Reputation: 11662

You want transformation matrices. Use this matrix to apply a translation of (tx,ty) for a 2D-vector (x,y):

translation

And this matrix for a rotation by theta:

enter image description here

Multiple translations and rotations can be combined by simply multiplying the matrices. (The order is important.)

Upvotes: 1

Peter Lawrey
Peter Lawrey

Reputation: 533820

You can use a matrix translation perform offsets, rotations and scaling. You can combine these by multiplying the matrices together.

Upvotes: 0

Related Questions