View previous topic :: View next topic |
Author |
Message |
runtime
Joined: 15 Sep 2003 Posts: 36
|
GPS reading: lat & lon points inside a predefined circle |
Posted: Mon Jul 26, 2004 6:40 pm |
|
|
Hello all,
Suppose I have a fixed point (lat & lon in decimal degrees), I want to use that point as a center for a circle of lets say 50 m radius. The GPS readings comes in about 1 per second, how can I check if the reading is inside the circle? (or 50 meters or less from fixed point) is the Great Circle method suitable for this? I've read that using trig functions will take too much cpu time...
for example:
point 1 (fixed point):
lat1: 14.56551
lon1: -90.50827
point2:
lat2: 14.55508
lon2: -90.52595
How do I check if point2 is 50 m or less from point1?
Does someone has done this?
Thank you in advance
Peter |
|
|
Thomas Blake
Joined: 18 Jan 2004 Posts: 22 Location: Burbank CA
|
Circle Intersection |
Posted: Mon Jul 26, 2004 7:31 pm |
|
|
There are a number of ways to do this, but first let's assume you know the portion of a degree that 50m represents. This may vary in the least significant bits between measurements at the Equator and near the poles, but that's a second-order effect that you'll have to add in later if necessary.
The Pythagorean Theorem is probably the most efficient way of dealing with this. Construct a conceptual right triangle with sides (lon1 - lon2) and (lat1 - lat2). Don't worry about the order; negative numbers are OK. The result will eventually be an absolute value.
So of course the distance c between point a = (lat1, lon1) and b = (lat2, lon2) is
c = sqrt(a*a + b*b);
This will be in units of degrees. You then just need to scale by the ratio of 50m to 1 degree.
The use of floats in your code is actually going to be the thing that slows down the program. If you are working with a fixed number of significant digits, you might want to do this in arbitrary-point arithmetic.
Regards
tcb |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Jul 26, 2004 7:37 pm |
|
|
Since we know that 50 * 50 = 2500, you can speed things up by not having to take the square root |
|
|
Konrad
Joined: 15 Sep 2003 Posts: 34
|
|
Posted: Tue Jul 27, 2004 4:35 pm |
|
|
Note that for LAT and LONG normal geometry is only accurate for small distances, such as 50m. for larger distances, search the web for "Aviation Formulary". |
|
|
Birdasaur
Joined: 07 Oct 2003 Posts: 29
|
Square is easier than a circle |
Posted: Wed Sep 15, 2004 11:41 am |
|
|
I've done bounding box checks using a similar GPS module and a 16f877. Not that this answers your original question but if you could, I would use a square that tightly fits your circle area. Bounding violations can easily be computed doing that with only one point. |
|
|
Guest
|
|
Posted: Thu Sep 16, 2004 2:17 am |
|
|
50 m is cca. 0.00045° ( =50/40076590*360 )
After calculation you will have 1/4 of the original precision (square and square-root).
If you really want to do this then you have to check the actual number of visible satellites (there is a flag register to show the active sats) and you must have at least 5 satellites to get a reasonable result. |
|
|
bdavis
Joined: 31 May 2004 Posts: 86 Location: Colorado Springs, CO
|
|
Posted: Fri Sep 17, 2004 11:32 pm |
|
|
Can you use a PIC with hardware multiply? The PIC18Fxxx chips have that and can run at 40MHz or 10 MIPS. I think you can do it on a PIC at a sampling frequency of 1 Hz. I have the formula you are looking for, but don't remember it off the top of my head - I'll try to post it later... |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Sat Sep 18, 2004 8:30 am |
|
|
The bounding box is probably the way to go... One outside box that contains the circle and one inside box within the circle say 50m equals one degree...if the lat or the long differs by one degee it is outside the 50m circle... the inside box..is basic trig and is 50xcos(45) or35 miles so if either the lat or long differ by less than 35 miles (35/50 degree) it is within the 50 mile circle. Only do the a^2+b^2 =2500 calc between the 35 and 50 values |
|
|
|