Re: point on line
- Posted by tone.skoda at siol.net
Feb 25, 2002
-- 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
-- ADD THIS:
-- if x's are same then should
-- also y's be same, for point to be on line
if p1[1]-p[1] = 0 then
return 0
end if
if p1[1]-p2[1] = 0 then -- line is vertical
if p[0] = p1[0] then -- x's are same and line is vertical
return 1
else -- x's are not same and line is vertical
return 0
end if
end if
-- END ADD THIS.
return ( (p1[2]-p[2])/(p1[1]-p[1]) ) = ( (p1[2]-p2[2])/(p1[1]-p2[1]))
end function
----- Original Message -----
From: <bensler at mail.com>
To: "EUforum" <EUforum at topica.com>
Sent: Tuesday, February 26, 2002 2:20 AM
Subject: point on line
>
> 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
>
> Chris
>
>
>
>
|
Not Categorized, Please Help
|
|