ソースを参照

特殊情况绘制墙bug修复

haojianlong 4 年 前
コミット
003648c21a
1 ファイル変更8 行追加0 行削除
  1. 8 0
      src/utils/graph/generate.ts

+ 8 - 0
src/utils/graph/generate.ts

@@ -35,6 +35,14 @@ export class generate {
         const b = p2.y - k * p2.x;
         // 距离两条线l的点 到交点p2的距离
         const Lb2 = l / Math.sin(Math.abs(a1 - a2) / 2);
+        // 特殊情况-角分线垂直或平行X轴
+        if (k1 / k2 == -1) {
+            if (dx2 * dx1 > 0 && dy2 * dy1 < 0) { // 上下开角
+                return [Number((p2.x - Lb2).toFixed(6)), Number(p2.y.toFixed(6)), Number((p2.x + Lb2).toFixed(6)), Number(p2.y.toFixed(6))]
+            } else if (dx2 * dx1 < 0 && dy2 * dy1 > 0) { // 左右开角
+                return [Number(p2.x.toFixed(6)), Number((p2.y - Lb2).toFixed(6)), Number(p2.x.toFixed(6)), Number((p2.y + Lb2).toFixed(6))]
+            }
+        }
         // 将距离公式与直线方程连立,并且将直线方程代入,得到一元二次方程 Ax^2 + Bx + C = 0;然后根据得根公式得到2个解
         const A = k * k + 1;
         const B = 2 * k * b - 2 * p2.x - 2 * k * p2.y;