[GRASS5] [mshapiro@ncsa.uiuc.edu: bug in libes/gis/line_dist.c]
Carl Worth
cworth at east.isi.edu
Thu Feb 21 11:53:02 EST 2002
On Feb 21, Radim Blazek wrote:
> On Thursday 21 February 2002 13:45, Markus Neteler wrote:
> > Hi developers,
> > I was looking through the grass src code and found a bug in the
> > G_distance2_point_to_line() function in libes/gis/line_dist.c
> >
> > lines 47,48 should be changed from
> >
> > dx = dx * t + x1;
> > dy = dy * t + y1;
> > to
>
> I think that (dx * t + x1, dy * t + y1) is point x,y projected to line
> x1,y1->x2,y2 (comment in code: /* go t from x1,y1 towards x2,y2 */)
> and we want distance between this point and and x,y. That is:
> dx = dx * t + x1 - x;
> dy = dy * t + y1 - y;
>
> You should have someone double check me on this, though, just to be sure :)
I've double-checked this. Radim's fix above is correct.
You might even write it in the following (equivalent) way to make a
more clear parallel with the 3 cases above it in the code:
dx = x - (dx * t + x1);
dy = y - (dy * t + y1);
(the change of sign is not significant to the final result since both
dx and dy are squared at the end).
Cheers,
-Carl
--
Carl Worth
USC Information Sciences Institute cworth at east.isi.edu
3811 N. Fairfax Dr. #200, Arlington VA 22203 703-812-3725
More information about the grass-dev
mailing list