×
Namespaces

Variants
Actions
Revision as of 05:39, 26 July 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to calculate the direction of movement

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: Den123 (11 May 2008)
Last edited: hamishwillee (26 Jul 2012)

To calculate the direction of movement enough to know coordinates of two consistently received landmarks.

If you use the Cartesian coordinate system and adopt the longitude on the axis "X", latitude on the axis "Y" - then it is possible to calculate the vector of movement.

The following image demonstrates how to calculate vector of the movement and the angle of the vector:

DirectionOfMovement.png

Depending on the direction, you must perform correction of meaning angle.

The following code snippet demonstrates how to calculate the angle of the movements (relative to north), knowing consistently received two landmarks.

TReal alpha; // result
 
// calculate vector coordinates
TReal y = LatitudeB - LatitudeA,
x = LongitudeB - LongitudeA;
 
// hypotenuse
TReal sqrtResult = 0;
Math :: Sqrt( sqrtResult, x * x + y * y );
TReal angle;
Math :: ASin( angle, Abs( x ) / sqrtResult );
alpha = angle * 180 / KPi; // angle from North in degrees
 
// correction
if( x > 0 )
{
// I or IV quadrant
if( y < 0 )
{
// IV quadrant
alpha = 180 - alpha;
}
}
else
{
// II or III quadrant
if( y > 0 )
{
// II quadrant
alpha = -alpha;
}
else
alpha = alpha - 180;
}
This page was last modified on 26 July 2012, at 05:39.
69 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×