|
-
Feb 2nd, 2005, 05:26 AM
#1
Angles
My brain is giving up completely and I have the flu. 
Given a vector [5,-3], how do you work out the compass bearing?
Last edited by wossname; Feb 8th, 2005 at 08:35 AM.
I don't live here any more.
-
Feb 2nd, 2005, 05:38 AM
#2
Fanatic Member
Re: Angles
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.
-
Feb 5th, 2005, 06:17 AM
#3
Fanatic Member
Re: Angles
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))
sql_lall 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|