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??
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.


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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

785 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