- /**
- * 求直线AB, CD的交点
- * 如果平行, 返回null.
- *
- * @param a : Point
- * @param b : Point
- * @param c : Point
- * @param d : Point
- * @return Point - 交点
- * @usage <code>
- * import com.seyself.math.GeomMath;
- * var a = { x:0 , y:0 };
- * var b = { x:200 , y:200 };
- * var c = { x:100 , y:0 };
- * var d = { x:50 , y:200 };
- * trace( GeomMath.intersection( a, b, c, d ) ); // 输出 : (x=80, y=80)
- * </code>
- */
- 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 );
- }
求两直线的交点
最新推荐文章于 2024-08-06 19:43:10 发布
本文介绍了一种用于计算二维平面上两条直线交点的算法。若两直线平行,则返回null值;否则返回交点坐标。算法适用于由两点定义的直线,并通过实例展示了具体用法。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Qwen-Image-Edit-2509
图片编辑
Qwen
Qwen-Image-Edit-2509 是阿里巴巴通义千问团队于2025年9月发布的最新图像编辑AI模型,主要支持多图编辑,包括“人物+人物”、“人物+商品”等组合玩法
1491

被折叠的 条评论
为什么被折叠?



