Math question: direction calculation

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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
how do u want the direction expressed??
0
Author Commented:
degrees
0
Commented:
it's 3d, so degrees from which axis??
0
Author Commented:
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.

Thanks!
0
Commented:

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;
else
angle = 360 - angle_off_axis;

Andrew

0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Here are the sample values and results.

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

Result:
Magnitude: 1342 mm/s
Direction: 186.2 degrees

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

Result:
Magnitude: 1328 mm/s
Direction: 185.7 degrees
0
Author Commented:
Andrew,

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

Thanks.
0
Commented:
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:

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

0
Author Commented:
Thanks! I need time to check this. I will reply tomorrow.
0
Author Commented:
0
Author Commented:
Adjusted points from 50 to 100
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.