Re: GPS formulas
- From: Mark Borgerson <mborgerson@xxxxxxxxxxx>
- Date: Sat, 28 May 2005 22:18:26 -0700
In article <o7ame.17094$dZ5.1093342@xxxxxxxxxxxxxxxxxxxxx>, rsloan2003
@hotmail.com says...
> 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?
>
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.
>
> 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)
>
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.
> return C;
> }
Mark Borgerson
.
- References:
- GPS formulas
- From: Richard Sloan
- GPS formulas
- Prev by Date: GPS formulas
- Next by Date: CCD / CMOS affordable camera kits???
- Previous by thread: GPS formulas
- Next by thread: Re: GPS formulas
- Index(es):
Relevant Pages
|