geometry-challenged
Jim Hurley
jhurley at infostations.com
Mon Jan 26 12:47:46 EST 2004
>--
>
>Message: 2
>Date: Mon, 26 Jan 2004 06:57:50 -0500
>From: Jim Lyons <jimlyons at earthlink.net>
>Subject: Re: geometry-challenged
>To: use-revolution at lists.runrev.com
>Message-ID: <DDBA098E-4FF6-11D8-BEAE-000A95893982 at earthlink.net>
>Content-Type: text/plain; charset=US-ASCII; format=flowed
>
>Jim Hurley wrote in part:
>
>> I'm not sure if this helps, but the function "intersection" below
>> will return the intersection of any two lines.
>> ...
>>
>> function intersection p1,p2,pp1,pp2
>> ...
>>
>> return x & comma & y
>> end intersection
>
>Someone already pointed out that this function as written still allows
>one divide by zero case.
Jim
Check. I think the following handler takes care of the infinity.
One practical way to deal with the parallel lines case is to make
them converge to a point at a very great distance--see below. Or, of
course, you could return a "Lines parallel" message.
function intersection p1,p2,pp1,pp2
get the paramcount
if it is 1 then
put item 4 of p1 into pp2
put item 3 of p1 into pp1
put item 2 of p1 into p2
put item 1 of p1 into p1
end if
put item 1 of p1 into x1
put item 2 of p1 into y1
put item 1 of p2 into x2
put item 2 of p2 into y2
put item 1 of pp1 into xp1
put item 2 of pp1 into yp1
put item 1 of pp2 into xp2
put item 2 of pp2 into yp2
--Check if the lines are parallel and deal with it somehow
if (y2-y1)*(xp2-xp1) = (yp2-yp1)*(x2-x1) then add .0000001 to x2
if x1 = x2 or xp1 = xp2 then
if x2 = x1 then
return x1&comma&yp2 + (x1-xp2)*(yp2-yp1)/(xp2-xp1)
else
return xp2&comma& y2 + (xp1-x2)*(y2-y1)/(x2-x1)
end if
end if
put yp2 - y2 + x2*(y2-y1)/(x2 - x1) - xp2*(yp2 - yp1)/(xp2 - xp1)
into numerator
put ((y2 - y1)/(x2 - x1) -(yp2 - yp1)/(xp2-xp1)) into denom
put numerator / denom into x
put y2 + (x-x2) *(y2-y1)/(x2-x1) into y
return x & comma & y
end intersection
Jim
More information about the use-livecode
mailing list