Message: 4 Date: Sun, 25 Jan 2004 19:22:13 -0500 From: [EMAIL PROTECTED] Subject: Re: geometry-challenged To: [EMAIL PROTECTED] Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=iso-8859-1
sez [EMAIL PROTECTED]:I tried the function on two *non*-intersecting lines, and it gave me a "divide by zero" error. Not good. You need to find the mathematical intersection of the infinite lines defined by the two pairs of endpoints, and *then* decide whether or not that intersection point is within *both* of the line *segments* defined by said points.I'm not sure if this helps, but the function "intersection" below will return the intersection of any two lines.
------------------------------
Message: 5 Date: Sun, 25 Jan 2004 20:02:21 -0500 From: Brian Yennie <[EMAIL PROTECTED]> Subject: Re: geometry-challenged To: How to use Revolution <[EMAIL PROTECTED]> Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=US-ASCII; format=flowed
For the problem at hand, it should suffice to add a little if-logic to the beginning.
A line between two non-overlapping objects will always intersect exactly one of the sides of each object- you just have to pick the right one and _then_ use the intersection function.
With that said, an intersection function should probably error gracefully for parallel lines (i.e. non-intersecting).
- Brian
The function should yield the point of intersection of the two infinite lines defined by the line segments. It may or may not lie within the end points of either line segment.
Could you send me the points which gave you the error message.? (Notice that the values returned are not rounded. I you want to insert them as graphic points you may want to return round(x) & comma & round(y).)
Thanks,
Jim.
P.S. The following function helps to deal with the problem of parallel lines.
function intersection p1,p2,pp1,pp2
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
if x1 = x2 or xp1 = xp2 then
if x1 = x2 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
if (y2-y1)/(x2-x1) = (yp2-yp1)/(xp2-xp1) then add .0000001 to y2--if lines are parallel
-- This produces a VERY large x or y coordinate. Parallel for all practical purposes.
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
_______________________________________________ use-revolution mailing list [EMAIL PROTECTED] http://lists.runrev.com/mailman/listinfo/use-revolution
