Solved

# Math question: direction calculation

Posted on 2000-04-11
203 Views
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.
0

LVL 2

Expert Comment

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

Author Comment

ID: 2706246
degrees
0

LVL 2

Expert Comment

ID: 2706249
it's 3d, so degrees from which axis??
0

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.

Thanks!
0

LVL 5

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

Andrew

0

Author Comment

ID: 2706780
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 Comment

ID: 2706785
Andrew,

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

Thanks.
0

LVL 1

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:

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

0

Author Comment

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

Author Comment

ID: 2718319
0

Author Comment

ID: 2718321
Adjusted points from 50 to 100
0

## Featured Post

### Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their waâ€¦
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base classâ€¦
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor anâ€¦
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.