Re: point on line
- Posted by petelomax at blueyonder.co.uk Feb 25, 2002
- 392 views
On Tue, 26 Feb 2002 01:20:39 +0000, bensler at mail.com wrote: > >This function will fail with 'divide by zero' errors > >Can I fix this easily? I'm stumped. > >-- check if p is on the line defined by p1 and p2 >function point_on_line(sequence p, sequence p1, sequence p2) > if equal(p,p1) or equal(p,p2) then return 1 end if > return ( (p1[2]-p[2])/(p1[1]-p[1]) ) = ( (p1[2]-p2[2])/(p1[1]-p2[1])) >end function > If p1[1]-p[1] is zero it implies p & p1 is a horizontal line, therefore if p1[2]-p[1] is also zero the point is on the line, otherwise not. I haven't checked this or thought about it alot though. Pete