求两直线的交点
2013年03月01日
⁄ 综合
⁄ 共 1070字 ⁄ 字号
小 中 大
- public static function intersection( a:Object, b:Object, c:Object, d:Object ):Point
- {
- var pos1 = (b.y-a.y)/(b.x-a.x);
- var pos2 = (d.y-c.y)/(d.x-c.x);
- var pi = Number.POSITIVE_INFINITY;
- var ni = Number.NEGATIVE_INFINITY;
-
- if(pos1==pos2){
- return null;
- }
- if( pos1 == ni || pos1 == pi ){
- pos1 = b.y-a.y;
- }
- if( pos2 == ni || pos2 == pi ){
- pos2 = d.y-c.y;
- }
-
- var nx = ( ( a.x*pos1 ) - a.y - ( c.x*pos2 ) + c.y )/( pos1-pos2 );
- var ny = pos1*( nx-a.x ) + a.y;
-
- return new Point( nx, ny );
- }