GPS formulas

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
I have been looking for formulas to help me create a special GPS device, I
need to know distance from current position to a point (LAT,LONG) and also I
need a function to let me know when I am passing by a point and if its to
the left, right, ahead, or behind me, and it would be nice to know by how
much.

Below are formula I found on the web and thought would be at least part of
my answer, these were referred to as great circle equations.

I am not a math wiz, I am very good at math, but not to the point I could
come up with these equations myself :-)

Can anyone help with whats required?

Thanks!
Richard.

Now for the distance I have used successfully:
dLAT = LAT1 - LAT2;
dLONG = LONG1 - LONG2;
R = 6731000.0
double dist2(void) {
 return R*2*asin(sqrt((sin((dLAT)/2))*(sin((dLAT)/2)) +
cos(LAT1)*cos(LAT2)*(sin((dLONG)/2))*(sin((dLONG)/2))));
}

And for nearing I have used rather unsuccessfully:
double bearing(void) {
 C =
fmod(atan2(sin(dLONG)*cos(LAT2),cos(LAT1)*sin(LAT2)-sin(LAT1)*cos(LAT2)*cos(dLONG)),
2*PI);
 C = ((C*180)/PI)

 return C;
}



Re: GPS formulas
@hotmail.com says...
Quoted text here. Click to load it

If the point is fixed, you can simplify your calculations by pre-
calculating the sin and cosine of its latitude and longitude.

If processing time is at all a concern, you can also assume that
the sine and cosine of your own position  are also the same as
the sine and cosine of the point.   There will be an error--that
will disappear as you approach the point.

Quoted text here. Click to load it
fmod(atan2(sin(dLONG)*cos(LAT2),cos(LAT1)*sin(LAT2)-sin(LAT1)*cos(LAT2)*cos(dLONG)),
Quoted text here. Click to load it

If you want to avoid excessive trig,  first calculate the distance as
sqrt( mNorth *mNorth  + mEast * mEast)  where the north and east
distances are in meters.  You can get these numbers with very simple
plane trignometric calculations based on latitude, longitude and
the radius of the earth.

When you have meters north and east to the point, the determination
of bearing is a simple atan2() calculation.

These assumptions work nicely if you only need bearing to the nearest
degree and the distance is less than 40 or 50 kilometers.
If the distance is much larger, you are probably stuck with the more
complex spherical trignometric equations.


Quoted text here. Click to load it

Mark Borgerson

Re: GPS formulas
Quoted text here. Click to load it
fmod(atan2(sin(dLONG)*cos(LAT2),cos(LAT1)*sin(LAT2)-sin(LAT1)*cos(LAT2)*cos(dLONG)),
Quoted text here. Click to load it


The great circle formulae get increasingly inaccurate when
you get near the waypoint. This is because the great circle
distance is calculated as the sine or cosine of the route
seen from Earth's center (6400 kilometers / 4000 miles away).
The accuracy of the trigonometric functions will play a
significant role in short distances.

The shortest route (great circle route) will have a changing
heading (direction) unless the route is north-south or along
the equator. There is a little longer route with a constant
heading called the rhumbline.

One reference is <http://williams.best.vwh.net/avform.htm .
There are plenty of others, Google for 'great circle navigation'.

HTH

--

Tauno Voipio, CPL(A), aeronautic navigation instructor
tauno voipio (at) iki fi


Re: GPS formulas
Quoted text here. Click to load it






Pretty much guaranteed to be wrong at this point already.

Differences between longitudes don't have much of a useful meaning.
First because longitude is circular, and difference across a
wrap-around will yield wild results.  Second because the meaning of a
longitude difference changes with latitude.  The best way to generate
such formulae is usually to not use longitude and latitude at all, but
3D cartesian coordinates of points either on the unit sphere, or on
the actual earth surface --- those will even be easier to extract from
GPS raw signals, as an extra bonus.

The distance between two such points along the earth's surface is then
roughly

    arccos(dotproduct(point1, point2))/R

the length of an arc along the great circle through the two points.  I
say "roughly" because earth isn't really a sphere.

Generally, two points on the sphere, together with the center, define
a plane in space.  The intersection of that plane with the sphere is a
great-circle, and the shortest path between the two points is part of
it.

--
Hans-Bernhard Broeker ( snipped-for-privacy@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.

Re: GPS formulas
Quoted text here. Click to load it

The above formula will cause all sorts of grief for short
distances.  Due to (in)accuracy of the acos() function for
small angles, the computed result will be quite erratic
for two points that are very close to each other.

Quoted text here. Click to load it

Re: GPS formulas

[...]

Quoted text here. Click to load it


That grief is due to the problem being numerically tricky, though, not
because of the formula being wrong.  The formula cited by the OP will
have very similar problems: differences among longitudes and latitudes
of nearby points will lose up to 5 decimal digits to cancellation (GPS
resolution vs. range), even before any trigonomtric function is
called.

--
Hans-Bernhard Broeker ( snipped-for-privacy@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.

Re: GPS formulas
Quoted text here. Click to load it

That'a why a plain plane trigonometry formula with latitude
correction gives the best results on short tracks. Take one
degree to correspond 111.11 km and multiply the east-west
(longitude) difference with the cosine of the avreage latitude
of the track, then use Pythagoras' theorem for the rest.

--

Tauno Voipio
tauno voipio (at) iki fi


Re: GPS formulas
Quoted text here. Click to load it

I've used a similar approach: calculate the km/degree of latitude factor for
the average latitude of the two points, and then use Pythagoras.

This approach is simple, gives increasingly accurate results with shorter
distances, but doesn't work too well near the poles or over very large
distances. Polar explorers and astronauts probably shouldn't use it.

Steve
http://www.fivetrees.com



Re: GPS formulas
On Sat, 28 May 2005 22:54:06 -0400, "Richard Sloan"

Quoted text here. Click to load it

Have a look at http://williams.best.vwh.net/avform.htm



--
Peter Bennett, VE7CEI  
peterbb4 (at) interchange.ubc.ca  
We've slightly trimmed the long signature. Click to see the full one.

Site Timeline