Message: 11 Date: Mon, 28 Mar 2005 10:59:45 -0500 From: Richard Miller <[EMAIL PROTECTED]> Subject: Re: Math wizardry To: How to use Revolution <[email protected]> Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=US-ASCII; format=flowed
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
Richard,
I'm not sure there is any "consistent" result for the angle between any two lines which is less than 180 degrees.
If you draw any two intersecting lines and ask, "What is the angle between them?" and you allow any answer less than 180, then surely there are two answers. Say one angle is 45 degrees then then other legitimate answer is 135 degrees.
However if you ask, "What is the angle between two lines?" and restrict yourself to answers less than 90 degrees, the answer is unique.
For example using the following two funcitons:
function theAngleBetween a1,a2 put abs(a1 - a2) into tDiff if tDiff >pi/2 then put pi - tDiff into tDiff return abs(tDiff) end theAngleBetween
function theLineAngle p1,p2
--Angle of line defined by the two points p1 and p2
get the paramcount
if it is 1 then
put line 2 of p1 into p2
put line 1 of p1 into p1
end if
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 theLineAngleThe function theAngleBetween will always return an angle "a" such that 0<a<pi/2
I think this is the number you want. If not, let me know.
(If you want degrees, multiply all angle in radians by 180/pi.)
Jim
_______________________________________________ use-revolution mailing list [email protected] http://lists.runrev.com/mailman/listinfo/use-revolution
