判断两直线平行
isIntersect3(line1, line2) { // 转换成一般式: Ax+By = C let a1 = line1.endPoint.y - line1.startPoint.y; let b1 = line1.startPoint.x - line1.endPoint.x; let c1 = a1 * line1.startPoint.x + b1 * line1.startPoint.y; //转换成一般式: Ax+By = C let a2 = line2.endPoint.y - line2.startPoint.y; let b2 = line2.startPoint.x - line2.endPoint.x; let c2 = a2 * line2.startPoint.x + b2 * line2.startPoint.y; // 计算交点 let d = a1 * b2 - a2 * b1; // 当d==0时,两线平行 if (d == 0) { return false; } else { var x = (b2 * c1 - b1 * c2) / d; var y = (a1 * c2 - a2 * c1) / d; // 检测交点是否在两条线段上 if ((isInBetween(line1.startPoint.x, x, line1.endPoint.x) || isInBetween(line1.startPoint.y, y, line1.endPoint.y)) && (isInBetween(line2.startPoint.x, x, line2.endPoint.x) || isInBetween(line2.startPoint.y, y, line2.endPoint.y))) { return true; } } return false; },
标签:直线,判断,line2,line1,endPoint,let,b2,平行,startPoint From: https://www.cnblogs.com/yaosusu/p/17295481.html