My brain is giving up completely and I have the flu. :(
Given a vector [5,-3], how do you work out the compass bearing?
Printable View
My brain is giving up completely and I have the flu. :(
Given a vector [5,-3], how do you work out the compass bearing?
Normalise it and dot it with the unit vector in the N dir: (0,1)
(5,-3) -> magnitude = sqrt(5^2 + 3^2) = root 34
normalised vector = ( 5/sqrt(34), -3/sqrt(34) )
Dot product:
A dot B = mag(A)*mag(B)*cos(theta)
If you want a bearing then you can subtract from 360 as appropriate.
Alternatively, you know:
(5, -3) = r*(cos(theta), sin(theta)) where theta = 90 - bearing
- think 5 - 3i = r cis(theta)
also, r = length = sqrt(34)
so, really:
(5, -3) = (r sin(bearing), r cos(bearing))
=> tan(bearing) = 5 / -3
now, there are two options, one of which is obviously true, one of which is 180 degrees out.
(BTW, if it's in C++, you can use bearing = atan2(5, -3))