Go Down

Topic: calculate relative direction to destination (Read 631 times) previous topic - next topic

cutebuddy6

How to calculate the direction of the destination through EM406A

johnwasser

From http://www.movable-type.co.uk/scripts/latlong.html

Bearing
In general, your current heading will vary as you follow a great circle path (orthodrome); the final heading will differ from the initial heading by varying degrees according to distance and latitude (if you were to go from say 35°N,45°E (Baghdad) to 35°N,135°E (Osaka), you would start on a heading of 60° and end up on a heading of 120°!).

This formula is for the initial bearing (sometimes referred to as forward azimuth) which if followed in a straight line along a great-circle arc will take you from the start point to the end point:

Formula:   ? =   atan2(   sin(?long).cos(lat2),
cos(lat1).sin(lat2) ? sin(lat1).cos(lat2).cos(?long) )
JavaScript:   
var y = Math.sin(dLon) * Math.cos(lat2);
var x = Math.cos(lat1)*Math.sin(lat2) -
        Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
var brng = Math.atan2(y, x).toDeg();
Excel:   =ATAN2(COS(lat1)*SIN(lat2)-SIN(lat1)*COS(lat2)*COS(lon2-lon1),
       SIN(lon2-lon1)*COS(lat2))
* Note that Excel reverses the arguments to ATAN2 - see notes below
Since atan2 returns values in the range -? ... +? (that is, -180° ... +180°), to normalise the result to a compass bearing (in the range 0° ... 360°, with -ve values transformed into the range 180° ... 360°), convert to degrees and then use (?+360) % 360, where % is modulo.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

sbright33

Or you can use the other formula for a constant heading. 
For short distances this will be the same number.

At longer distances the distance traveled is significantly more.
The formula is about as long to calculate.
But it's easier to navigate with a compass if you're sailing.
How about a robot with a magnetic compass?
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

johnwasser


But it's easier to navigate with a compass if you're sailing.
How about a robot with a magnetic compass?


How about both.  The GPS to tell you where you are and the compass to tell you which way you are pointing.

Of course the GPS is not very accurate for short distances. That's why autonomous vehicles use cameras and laser range finders.  A Kinect would be suitable for building interiors.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

sbright33

My point, and question, is whether it is easier to use the constant heading formula for a long distant traveling robot?
Of course it doesn't matter for short distances.

I found one in the middle of the ocean last year, 200lbs, 8ft long.
A foam boat with a powerful motor and solar cells.
I guess it's not hard to implement so that the heading changes as you go.

For humans it's easier to look at a compass with a constant heading,
and it uses less battery power!  If you don't mind the scenic route...
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Go Up