# Compass heading from cartesian vectors?

1. Sep 19, 2009

### Artlav

Hello,

How can i calculate compass heading from cartesian vectors?

Specifically, a planet of radius R is located at (0,0,0), with north pole being at (0,R,0). An airplane is located at POS, and is flying in DIR direction.
How can i determine the (true north) compass heading of the plane?
DIR might not be parallel to the surface of the planet.

2. Sep 21, 2009

### willem2

you know how to project one vector on another?

The projection of v onto u, where u and v are both vectors in the same dimension euclidean vector space is:

$$\frac {u \cdot v}{ {|u|}^2}} u$$

You can use this to project the velocity vector (vx, vy, vz) on the position vector (x,y,z)

(x,y,z) points straight up (away from the center of the planet), so the projection of the velocity
vector on this vector gives the upward component of the velocity. Subtract this from the velocity
vector to get the horizontal velocity (along the surface). $v_{hor}$

what you then need to do is find a vector that points due east from the point (x, y, z)

you can then compute the angle between this vector and $v_{hor}$ to get the angle away from due east, and use the sign of vy to see if the direction is in the northern half of the compass.

3. Sep 21, 2009

### Artlav

So, projecting direction vector on the position vector, then subtracting it from the direction vector effectively projects the direction onto the local surface plane. Do the same thing with a vector pointing to the north pole, and you get the north-south part of the heading. Then, vector product of these two will give the direction east, allowing to find the full 360* angle.

Interesting. Thank you for the idea, it works.