博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
计算2条线的相交点
阅读量:5172 次
发布时间:2019-06-13

本文共 1388 字,大约阅读时间需要 4 分钟。

/** * crossPoint: 2条线相交的坐标 * line1: 坐标1的对象 * line2: 坐标2的对象 * pt = (x = 0, y = 0) 时不相交 */function crossPoint(line1, line2) {    // let line1 = {               line1, line2 结构相同    //     pStart: { x: 0, y: 0 },    //     pEnd: { x: 2, y: 2 },    // }    let pt = new egret.Point(0, 0)    // line1's cpmponent      let X1 = line1.pEnd.x - line1.pStart.x;//b1      let Y1 = line1.pEnd.y - line1.pStart.y;//a1      // line2's cpmponent      let X2 = line2.pEnd.x - line2.pStart.x;//b2      let Y2 = line2.pEnd.y - line2.pStart.y;//a2      // distance of 1,2      let X21 = line2.pStart.x - line1.pStart.x;    let Y21 = line2.pStart.y - line1.pStart.y;    // determinant      let D = Y1 * X2 - Y2 * X1;// a1b2-a2b1      //       if (D == 0) return pt;    // cross point      pt.x = (X1 * X2 * Y21 + Y1 * X2 * line1.pStart.x - Y2 * X1 * line2.pStart.x) / D;    // on screen y is down increased !       pt.y = -(Y1 * Y2 * X21 + X1 * Y2 * line1.pStart.y - X2 * Y1 * line2.pStart.y) / D;    // segments intersect.      if ((Math.abs(pt.x - line1.pStart.x - X1 / 2) <= Math.abs(X1 / 2)) &&        (Math.abs(pt.y - line1.pStart.y - Y1 / 2) <= Math.abs(Y1 / 2)) &&        (Math.abs(pt.x - line2.pStart.x - X2 / 2) <= Math.abs(X2 / 2)) &&        (Math.abs(pt.y - line2.pStart.y - Y2 / 2) <= Math.abs(Y2 / 2))) {        return pt;    }    return pt;}

 

转载于:https://www.cnblogs.com/H-K-Home/p/8810482.html

你可能感兴趣的文章
一次python 内存泄漏解决过程
查看>>
Python闭包与函数对象
查看>>
webview中文乱码
查看>>
2018GDKOI——记录
查看>>
[React] Use react-rewards to add microinteractions to React app to reward users for some actions
查看>>
[React] Style the body element with styled-components and "injectGlobal"
查看>>
[Angular2 Router] CanDeactivate Route Guard - How To Confirm If The User Wants To Exit A Route
查看>>
[Grunt] Cleaning your build folder with grunt-contrib-clean
查看>>
discuz!之XML解析错误:废弃 document 元素之后的内容错误
查看>>
jvm类加载机制
查看>>
洛谷P1976 鸡蛋饼
查看>>
HDU 5236 Article 期望
查看>>
hadoop操作
查看>>
架构1
查看>>
第2章 数字之魅——数组循环移位
查看>>
关于CoreData的用法
查看>>
python 结巴分词
查看>>
Eclipse插件手动安装
查看>>
iOS开发肯定会遇到的
查看>>
mysqlslap 一个MySQL数据库压力测试工具
查看>>