circular buffer around a central point

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TomGoodacre
Forum Newbie
Posts: 1
Joined: Sun Mar 14, 2004 9:53 am
Location: Manchester, UK
Contact:

circular buffer around a central point

Post by TomGoodacre »

I have a database full of OS grid references related to postcodes. I need to be able to extract all postcodes that appear a certain distance away from a postcode that a user enters.


so...

1. user enters postcode into form
2. easting (horizontal) and northing (vertical) grid references for entered postcode are retrieved from the database.
3. PHP used to locate all postcodes (by querying other easting and nothings) that are within a certain distance from postcode entered in stage 1.

The problem. This is fairly easy to do if you take the entered postcode and then draw a square around it of a certain size but I would like to be able to retrieve postcodes by drawing a circle around the entered postcode. Is this possible with PHP and if so how???

Complicated to explain I know - if there are any further questions just post back.

T
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: circular buffer around a central point

Post by TheBentinel.com »

TomGoodacre wrote: The problem. This is fairly easy to do if you take the entered postcode and then draw a square around it of a certain size but I would like to be able to retrieve postcodes by drawing a circle around the entered postcode. Is this possible with PHP and if so how???
I don't know enough to code it, but maybe I can get you started.

The x and y of a point on a circle is defined as:
x = centerPointX + (sine(radianOfCircle) * radiusOfCircle)
y = centerPointY + (cosine(radianOfCircle) * radiusOfCircle)

radianOfCircle is a bad name, but I'm trying to convey that it's where on the circle the point is. What degree it is, except in radians instead of degrees.

(I may have the sine/cosine's reversed. And I may be wrong altogether!)

Does that help you draw your circle?

The sine and cosine functions are sin() and cos().
There are 2PI (about 6.28) radians in a circle.

If I'm way wrong here, please correct me!
Post Reply