utils增加均分直线

This commit is contained in:
Yuan 2023-06-27 09:56:19 +08:00
parent 481062e30b
commit b1579c88c6

View File

@ -676,3 +676,20 @@ export function isLineContainOther(
isPointOnLine(line2.p1, line2.p2, line1.p2))
);
}
/** 均分线段, 返回各线段端点 */
export function splitLineEvenly(
p1: IPointData,
p2: IPointData,
count: number
): IPointData[][] {
const [stepX, stepY] = [(p2.x - p1.x) / count, (p2.y - p1.y) / count];
return Array(count)
.fill(1)
.map((_, i) => {
return [
{ x: p1.x + stepX * i, y: p1.y + stepY * i },
{ x: p1.x + stepX * (i + 1), y: p1.y + stepY * (i + 1) },
];
});
}