Search code examples
actionscript-3flashapache-flexflash-builder

How to calculate angle between two intersecting lines in Flex


If there is two lines line1 and line2 . How to calculate angle between these 2 lines.

If line1 has points {(x1,y1),(x2,y2)} and line2 has points {(x3,y3),(x4,y4)}

I know how to calculate the slopes .Any idea to calculate angle in flex.

Let the slopes is known....


Solution

  • var angleRadians:Number=Math.abs(Math.atan2(y2-y1,x2-x1)-Math.atan2(y4-y3,x4-x3));
    if (angleRadians>0.5*Math.PI) angleRadians=Math.PI-angleRadians;
    

    In short, get two slopes, subtract one from another, absolutize the result (the angle is positive) and since there are 4 angles around the intersection, so if we'll receive a bigger one, make a smaller out of it.