1. 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

new topic     » topic index » view message » categorize

2. Re: point on line

-- 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
>
>
>
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: point on line

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

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu