# Longitude and Latitude co-ordinates within a given circle.

Dear Experts

Is it possible to come up with some sort of formula which can find all possible longitude and latitude co-ordinates within a circle when given the center of a circle.  The circle has a radius of 0.05 Miles.  The center point is given in longitude and latitude co-ordinates also.

Thanks
LVL 1
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
>> all possible longitude and latitude co-ordinates

There are infinitely many (and uncountable on top of that), so no.

Maybe you should specify why you need this ...

All points (x, y) in a circle with center (x0, y0) and radius R make these true :

(x - x0)² + (y - y0)² <= R²
0
Commented:
for longitude and latitude co-ordinates, that's a good approximation for short distances near the equator, but in general this is better
http://williams.best.vwh.net/avform.htm#Dist

For short distances like 0.05 Miles, not too close to the poles,
a reasonable approximation could be
(x - x0)² + ((y - y0)/cos(x))² <= R²
0
Commented:
I was thinking of a circle on a Mercator projection map ... But you're right to point this out.

Although, 0.05 miles is a very small radius, and the difference between the true distance on the Earth's surface and the approximated distance sqrt((x-x0)² + (y-y0)²) will be very small.
0
Commented:
>> and the difference between the true distance on the Earth's surface and the approximated distance sqrt((x-x0)² + (y-y0)²) will be very small.

Sentence continued : ... will be very small on that scale.
0
Commented:
On a Mercator projection map, the circle will still be distorted as you move away from the equator
on any scale (y-y0) should still be adjusted by a factor of cos(x)
(x - x0)² + ((y - y0)/cos(x))² <= R² should have been
(x - x0)² + ((y - y0)*cos(x))² <= R²
assuming y is longitude and x is latitude
0
Commented:
>> On a Mercator projection map, the circle will still be distorted as you move away from the equator

I mean an actual circle drawn on the map using a compass. It was probably the wrong interpretation anyway :)
0
Commented:
> circle drawn on the map using a compass.
On a Mercator map, (x - x0)² + (y - y0)² still only works near the equator, since the latitude scale gets distorted away from the equator.
0
Commented:
>> since the latitude scale gets distorted away from the equator.

Mm ... I see what you mean now. And I stand corrected.
0
Author Commented:
Thanks for the replies, very informative.  How will it get effected if the radius is 3 Miles or 5 Miles?  Ideally, I should be able to change the radius from 0.01 miles upto about 30 miles
0
Commented:
(x - x0)² + ((y - y0)*cos(x))² might still be ok if you're more than 3000 miles from a pole.
0
Author Commented:
>> There are infinitely many (and uncountable on top of that), so no.

I have a list of some co-ordinates in longitude and latitude, and basically I need to know if they fit into the circle.

>> I mean an actual circle drawn on the map using a compass. It was probably the wrong interpretation anyway :)

I was hoping for a formular which was more accurate, i.e. takes into account the curvature of the planet

>> (x - x0)² + ((y - y0)*cos(x))² might still be ok if you're more than 3000 miles from a pole.

What happens if the center of the circle is closer to the poles.  What formular would be needed then?
0
Commented:
0
Commented:
0
Commented:
>> I was hoping for a formular which was more accurate, i.e. takes into account the curvature of the planet

0
Author Commented:
>> http://williams.best.vwh.net/avform.htm#Dist
>> http://www.movable-type.co.uk/scripts/gis-faq-5.1.html
>> Yep ... ozo's posts should help you better than mine :)

I went to those links and just wanted to confirm if this is what I am after?...

A point {lat,lon} is a distance d out on the tc radial from point 1 if:

lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
IF (cos(lat)=0)
lon=lon1      // endpoint a pole
ELSE
lon=mod(lon1-asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi
ENDIF

#################
specifically this part

This algorithm is limited to distances such that dlon <pi/2, i.e those that extend around less than one quarter of the circumference of the earth in longitude. A completely general, but more complicated algorithm is necessary if greater distances are allowed:

lat =asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
dlon=atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(lat))
lon=mod( lon1-dlon +pi,2*pi )-pi

How accurate is this when more than 3000 miles from the poles to less than 3000 miles from the poles?
0
Commented:
The more general algorithm works anywhere.
The less general algorithm works for when you are dealing with distances < d when you are > d from the poles.
0
Author Commented:
I'm confused...
0
Commented:
you can use

lat =asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
dlon=atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(lat))
lon=mod( lon1-dlon +pi,2*pi )-pi

anywhere

you can use
lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
IF (cos(lat)=0)
lon=lon1      // endpoint a pole
ELSE
lon=mod(lon1-asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi
ENDIF
for d<3000 miles when more than 3000 miles from the poles
or for d<30 miles when more than 30 miles from the poles
or for d<0.05 miles when more than 0.05miles from the poles
0
Author Commented:
Thanks,

So how do I apply this if I have the center point here:

lat:41.902277040963696
lng:-99.84375

with a radius of 5 miles

using the following formula:

lat =asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
dlon=atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(lat))
lon=mod( lon1-dlon +pi,2*pi )-pi
0

Experts Exchange Solution brought to you by