CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

GPS reading: lat & lon points inside a predefined circle

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
runtime



Joined: 15 Sep 2003
Posts: 36

View user's profile Send private message

GPS reading: lat & lon points inside a predefined circle
PostPosted: Mon Jul 26, 2004 6:40 pm     Reply with quote

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

View user's profile Send private message

Circle Intersection
PostPosted: Mon Jul 26, 2004 7:31 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 26, 2004 7:37 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jul 27, 2004 4:35 pm     Reply with quote

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

View user's profile Send private message

Square is easier than a circle
PostPosted: Wed Sep 15, 2004 11:41 am     Reply with quote

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








PostPosted: Thu Sep 16, 2004 2:17 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Sep 17, 2004 11:32 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Sat Sep 18, 2004 8:30 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group