converting kph and heading to xyz velocity vector

4.2k Views Asked by At

I am writing software (in C++) that is required to send out messages from our simulation system to another simulation system. Problem is we track the simulation object's current speed (kph) and heading (degrees) the other system needs a Velocity vector which is XYZ.

I have no idea how to do this. I unfortunately have a very weak trigonometry background and don't really understand vectors. I just need a formula to do the conversion. I could not find anything out there. Please....

2

There are 2 best solutions below

1
On

So what you're looking to do from a math perspective is go from spherical coordinates to Cartesian coordinates.

Basically your velocity vector in spherical coordinates includes three pieces of information: speed, horizontal heading, and vertical heading. You want your velocity vector in terms of X,Y, and Z. To do this, we use these equations:

$x=r \, \sin\theta \, \cos\phi$

$y=r \, \sin\theta \, \sin\phi$

$z=r \, \cos\theta$

Where $r$ is your speed, $\phi$ is your horizontal bearing, and $\theta$ is your vertical bearing.

Note: you didn't actually mention that you had a vertical bearing. I'm assuming you do since you asked for an X,Y,Z vector.

There's some more information on spherical coordinates here on mathworld.

1
On

You can calculate your vertical bearing theta if you also have your clime rate.

So for example if your clime rate is -20 ft/sec (aka descending) and your horizontal speed is 100 ft/sec. Now in one sec you will have traveled 100 feet forward and 20 feet down

Then Tan(theta) =-20/100

theta = Atan2(-20/100)

This return value will be in radians

theta = -0.1973955 Rad

theta = -11.31 Deg