views:

159

answers:

1

Right now in Matlab (0,0) is the origin, 0 degrees / 2pi would be to the right of the cartesian plane and angles are measured counter clockwise with 90 degrees being at the top.

I'm trying to write a simulator where the coordinates would match a compass bearing. 0/360 degrees or 2pi would be at the top and 90 degrees would be on the right.

Any idea how to code in Matlab or c++? I'd imaging it'd be a matrix flipped about the x axis and rotated 90 degrees but I'm at a total loss.

Phil

+2  A: 

You need do nothing more than swap x and y coordinates. This is a reflection in the line x=y. No need to use a matrix or anything. Just swap coordinates before using them. If you really insist on applying a matrix then

[0 1]
[1 0]

swaps x and y.

So from the origin, if I have a target 10 meters out and it's at 60 degrees (2 o'clock position), the (x,y) location in cartesian space would be (10sin(60), 10cos(60))?
pinnacler
Aha! I wasn't sure what you were after but now I know. Yes, your formula is correct. Try it and see!
You seem to have simple answers... any idea how to rotate a matrix around a point other than the origin? Say I have a point at (3,5), how would I rotate a matrix clockwise around that point? I tried translating back to the origin by subtracting (3,5), rotating, then translating back by adding (3,5). It didn't seem to work. Could I have done it wrong or is there another way?
pinnacler
What you described is exactly right. One thing you could do is try transforming a bunch of points of a known shape and see where they end up. Maybe you did things back-to-front and ended up rotating around (-3,-5).