parent
f9bb2279e8
commit
ec89e355e6
@ -517,34 +517,3 @@ export function angleOfIncludedAngle(
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
/**
|
||||
* 判断点是否在线段上
|
||||
* @param point 判断点
|
||||
* @param start 线段起点
|
||||
* @param end 线段终点
|
||||
* @returns
|
||||
*/
|
||||
export function isPointOnLineSegment(
|
||||
point: IPointData,
|
||||
start: IPointData,
|
||||
end: IPointData
|
||||
) {
|
||||
// 计算向量AB和向量AC的叉积
|
||||
const crossProduct =
|
||||
(end.y - start.y) * (point.x - start.x) -
|
||||
(end.x - start.x) * (point.y - start.y);
|
||||
|
||||
// 如果叉积为0,则点在直线上
|
||||
if (crossProduct === 0) {
|
||||
// 接下来判断点是否在线段上
|
||||
if (
|
||||
point.x >= Math.min(start.x, end.x) &&
|
||||
point.x <= Math.max(start.x, end.x) &&
|
||||
point.y >= Math.min(start.y, end.y) &&
|
||||
point.y <= Math.max(start.y, end.y)
|
||||
) {
|
||||
return true; // 点在线段上
|
||||
}
|
||||
}
|
||||
return false; // 点不在线段上
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user