Last active
October 6, 2015 00:17
-
-
Save tmshv/2901554 to your computer and use it in GitHub Desktop.
calc cross coord (as3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* return coordinate of crossing two lines defined by {x1; y1}, {x2; y2} | |
* @param l1 | |
* @param l2 | |
* @return | |
*/ | |
private static function getCrossCoord(coef1:Object, coef2:Object):Point { | |
var a1:Number = coef1.a; | |
var b1:Number = coef1.b; | |
var c1:Number = coef1.c; | |
var a2:Number = coef2.a; | |
var b2:Number = coef2.b; | |
var c2:Number = coef2.c; | |
var cross:Point = new Point( | |
(c2 * b1 - c1 * b2) / (a1 * b2 - a2 * b1), | |
(c2 * a1 - c1 * a2) / (b1 * a2 - b2 * a1) | |
); | |
return cross; | |
} | |
/** | |
* return the free coefficient of base line formula | |
* @param x1 | |
* @param y1 | |
* @param x2 | |
* @param y2 | |
* @return | |
*/ | |
private static function getLineCoefs(x1:Number, y1:Number, x2:Number, y2:Number):Object { | |
return { | |
a:y2 - y1, | |
b:x1 - x2, | |
c:(y1 * x2) - (x1 * y2) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment