Math question: direction calculation

Posted on 2000-04-11
Last Modified: 2010-04-02
If I have values for east/west, north/south and vertical velocities, how do I calculate the resulting direction taking all of them into account?

Will increase points on suitable answer.
Question by:skanade

Expert Comment

ID: 2706216
how do u want the direction expressed??

Author Comment

ID: 2706246

Expert Comment

ID: 2706249
it's 3d, so degrees from which axis??
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.


Author Comment

ID: 2706370
Frankly, I don't know. But, I use a program that shows the value already. I don't have the code. I suppose, if I give you three values and a result, will you be able to find it out? I guess so. Please give me some time to give you the values.


Accepted Solution

pitonyak earned 100 total points
ID: 2706439

Are you given information such as...

3 m/sec East
4 m/sec North

If so, the combined velocity will be given by a right triangle with the east leg a length of 3 and the north leg of length 4. If you have a right triangle you can use things such as:

Leg1^2 + Leg2^2 = Hypotenuse^2

In our case, this yields...

9 + 16 = 25 so the real velocity is 5 m/sec (the square root of 25)...

So, assume that you are given two velocities v1 and v2, you can determine the actual velocity as

v = sqrt(v1*v1 + v2*v2);

Now here is where the fun begins.... You want to know in which direction you are really going... I assume that you want an angle. If this is the case then you should note a few things...

1) Your compiler probably deals in radians and you probably think in degrees so if you say that you went turned 90 degrees to the left, your computer would probably say that you turned about 1.5707963268 rads to your left. I will state the problem in degrees since this is how I think.

This said, I will assume that you will use trigonometry to solve your problem.

I will assume

pi = 3.14159265359
East = 0 degrees = 0 radians
North = 90 degrees = pi/2 radians
West = 180 degrees = pi radians
South = 270 degrees = 3*pi/2 radians

In general, if I want to know the angle, assume that I am traveling

3 m/sec East
4 m/sec North
5 m/sec North-East

The real direction x is given using trig...

sin(x) = opposite/hyp = 4/5 = .8
cos(x) = adjacent/hyp = 3/5 = .6
tan(x) = opposite/adjacent = 4/3 = 1.33333

I can then have that

atan(1.3333) = acos(.6) = asin(.8) = 53.13 degrees = 0.927295218002 radians.

Note that if you have an answer in radians and you want to convert it to degrees, you can simply multiply by 180 and divide by pi.

Note that this will only hold (without doing fancy stuff) if you stick with right triangles (triangles with a 90 degree angle in them).

How you interpret the directions is based soley upon the right triangle that you draw and how you interpret it.

I will assume now that
3 m/s West = -3 m/s East
4 m/s South = -4 m/s North

I will draw ALL of my triangles off of the East/West axis so...

double east;
double north;
double v = sqrt(east*east + north*north); // velocity
double pi2 = asin(1); // note that asin(1) = pi/2 or 90 degrees
double angle_off_axis = asin(fabs(east) / v) * 90 / pi2; // converted to degrees
double angle;
if (east >= 0 && north >= 0)
    angle = angle_off_axis;
else if (east < 0 && north >= 0)
    angle = 180 - angle_off_axis;
else if (east < 0 && north < 0)
    angle = 180 + angle_off_axis;
    angle = 360 - angle_off_axis;



Author Comment

ID: 2706780
Here are the sample values and results.

E/W: -145 mm/s
N/S: -1334 mm/s
Vertical: -27 mm/s

Magnitude: 1342 mm/s
Direction: 186.2 degrees

E/W: -133 mm/s
N/S: -1321 mm/s
Vertical: -20 mm/s

Magnitude: 1328 mm/s
Direction: 185.7 degrees

Author Comment

ID: 2706785

I will need time to understand your comment as it is a little complicated for me.


Expert Comment

ID: 2707191
pitonyak, I'm afraid you forgot the vertical velocity.
here,(simply) are the co-ordinates you need are:

Magnitude = sqrt( E/W^2+N/S^2 + Vertical^2)

(in every dimension, 3 in our case, the magnitude is the square root of sum of squares of all the directions)

Now, for direction, you only needed the horizontal direction so:
Direction=arctan (absolute(E/W)/absolute(N/S))
all you need to determine, is in which quarter you are in, in order to compute the real direction:

   180 - Direction  |   Direction
        -------------------------- N/S
    180+Direction   |  360-Direction



Author Comment

ID: 2708585
Thanks! I need time to check this. I will reply tomorrow.

Author Comment

ID: 2718319
Sorry about that, but the previous comment already answered the main question in great detail.

Author Comment

ID: 2718321
Adjusted points from 50 to 100

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question