Re: Distance from point to box

Поиск
Список
Период
Сортировка
От Alexander Korotkov
Тема Re: Distance from point to box
Дата
Msg-id CAPpHfdsDuvucZGwvtdOUCQ8x1crmLhaRMEiHDKVJiUx38VDE_Q@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Distance from point to box  (Fabien COELHO <coelho@cri.ensmp.fr>)
Ответы Re: Distance from point to box  (Fabien COELHO <coelho@cri.ensmp.fr>)
Список pgsql-hackers
On Wed, Jul 30, 2014 at 4:06 PM, Fabien COELHO <coelho@cri.ensmp.fr> wrote:

double dx = 0.0, dy = 0.0;

if (point->x < box->low.x)
   dx = box->low.x - point->x;
if (point->x > box->high.x)
   dx = point->x - box->high.x;
if (point->y < box->low.y)
   dy = box->low.y - point->y;
if (point->y > box->high.y)
   dy = point->y - box->high.y;
return HYPOT(dx, dy);

I feel myself quite tangled.
Could anybody clarify it for me? Did I miss something? Thanks.

ISTM that you miss the projection on the segment if dx=0 or dy=0.

I don't need to find projection itself, I need only distance. When dx = 0 then nearest point is on horizontal line of box, so distance to it is dy. Same when dy = 0. When both of them are 0 then point is in the box.

------
With best regards,
Alexander Korotkov.  

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Fabien COELHO
Дата:
Сообщение: Re: Distance from point to box
Следующее
От: desmodemone
Дата:
Сообщение: Re: Proposal: Incremental Backup