Thanks to help from Jim Hurley, I can now compute the angles of separate, but interesecting, lines, each relative to the horizontal.

So I've got these two angles. But I'm not having any success figuring out (consistently and accurately) what the angle is between the two lines. I'm only interested in the less-than-180-degree angle. The problem is not knowing from which direction these lines were drawn by the user. There are four possible combinations:

- drawing from one endpoint to the intersecting point, then from the intersecting point to the endpoint of the other line;

- drawing from one endpoint to the intersecting point, then drawing the second line from its endpoint back to the intersecting point;

- drawing from the intersecting point to the end point of the first line, then from the intersecting point to the endpoint of the other line;

- drawing from the intersecting point to the end point of the first line, then from the end point of the second line back to the intersecting point.

All of these give different values for the resulting angles, depending on the direction from which the lines are drawn. How do I consistently determine the angle between the two lines?

Thanks.
Richard Miller
Imprinter Technologies


On Mar 2, 2005, at 12:25 PM, Jim Hurley wrote:


Message: 1 Date: Wed, 2 Mar 2005 10:41:27 -0500 From: Richard Miller <[EMAIL PROTECTED]> Subject: Math wizardry To: How to use Revolution <[email protected]> Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=US-ASCII; format=flowed

I've got two line graphics drawn on the screen. I need to find out if
they intersect and, if so, what the angle is that is formed by their
intersection. Any simple way to do this?

Thanks.
Richard Miller
Imprinter Technologies


Richard,

Here are a couple of functions which will should be helpful:

function theLineAngle p1,p2
  --Angle of line defined by the two points p1 and p2
  put item 1 of p2 - item 1 of p1 into dx
  put item 2 of p2 - item 2 of p1 into dy
  put atan2(dy,dx) into tAngle
  return tAngle
end theLineAngle

And

function intersection line1,line2
--Intersection point of two lines defined by line1 and line2
--Where line1 is defined by its two end points x1,y1,x2,y2
put item 1 to 2 of line1 into p1
put item 3 to 4 of line1 into p2
put item 1 to 2 of line2 into pp1
put item 3 to 4 of line2 into 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 and xp1= xp2 then add .0001 to xp2
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 .0001 to y2--if lines are parallel
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


You may wish to handle the special cases were the lines intersect at infinity differently. In the above function I have chosen to slightly alter the given points so that the lines intersect at a great distance (close to infinity, so to speak.)

The above intersection function assumes that these are effectively the infinite lines of Euclidean geometry. The end points are simply two points which define the infinite lines. To find out whether the intersection point lies between the end points of each line you will need to test whether the distance between the intersection point and ALL the end points is less than the length of each line respectively. (I can't imagine that sentence is clear.)

Other functions which might be helpful are the perpDist function (the perpendicular distance between a point and a given line, and thePerpProj function (the perpendicular projection of a given point onto a line.) You can see how these work in my recent Bouncing Ball post which can be retrieved by putting this into the msg box:

go url  http://home.infostations.net/jhurley/BouncingBallTools.rev

Let me know if you have any  problems.

Jim

P.S. I've currently lost my mind entirely and am working on a simulation of pool. So far I've got the balls (just two balls) colliding and rebounding so that they satisfy the physical laws of collision dynamics. What fun.
_______________________________________________
use-revolution mailing list
[email protected]
http://lists.runrev.com/mailman/listinfo/use-revolution



_______________________________________________ use-revolution mailing list [email protected] http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to