php - SQL: search of nearest in 2d square and circle -


i have table: points

it has 2 filds: x, y

each row represents dot on 2d field

i want capable of performing search of dots in radius r

alt text

and square side

alt text

btw: use php access db.

my main point nearest center of figure point first result in quqe alt text

how such thing in sql?

mathematically point in circle statisfies equation

(c.x-p.x)^2 + (c.y-p.y)^2 <= r^2 

where c cetner of circle, p - point, r - radius

for square

max(abs(c.x-p.x),abs(c.y-p.y)) <= a/2 

where c cetner of square, p - point, a - side of square

you can write theese equations in language.

left side of equations called distance various measures. finding nearest point should order resultset distance asceniding , take first result.

something this:

select top 1 p.x, p.x points p otrder ((@x - p.x)*(@x - p.x)+(@y - p.y)*(@y - p.y)) 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -