代码同步

This commit is contained in:
fan 2023-06-16 10:28:39 +08:00
parent 834eb5ed95
commit 41c562451a
2 changed files with 66 additions and 1 deletions

@ -1 +1 @@
Subproject commit 8762ced5f8592db84ed19490cdb6c0322df874d8
Subproject commit ff5ed78027861c0af12c5bcfb8c073e362d282b0

View File

@ -542,3 +542,68 @@ export function angleOfIncludedAngle(
}
return angle;
}
/**
* 线
* @param point1
* @param point2
* @returns
*/
export function getNormalVector(
point1: IPointData,
point2: IPointData
): number[] {
const x1 = point1.x,
y1 = point1.y;
const x2 = point2.x,
y2 = point2.y;
const length = Math.sqrt((y2 - y1) ** 2 + (x2 - x1) ** 2);
return [(y2 - y1) / length, (x1 - x2) / length];
}
/**
*
* @param point
* @param normal
* @param length
* @returns
*/
export function movePointAlongNormal(
point: IPointData,
normal: number[],
length: number
): Point {
const newPoint = new Point(
point.x + length * normal[0],
point.y + length * normal[1]
);
return newPoint;
}
/**
* 线(线 )
* @param line1
* @param line2
* @returns
*/
export function getIntersectionPoint(line1: number[], line2: number[]) {
const a1 = line1[0],
b1 = line1[1];
const a2 = line1[2],
b2 = line1[3];
const a3 = line2[0],
b3 = line2[1];
const a4 = line2[2],
b4 = line2[3];
const denominator = (a3 - a4) * (b1 - b2) - (a1 - a2) * (b3 - b4);
if (denominator === 0) {
return new Point(a1, b1);
}
const x =
((a3 - a4) * (a2 * b1 - a1 * b2) - (a1 - a2) * (a4 * b3 - a3 * b4)) /
denominator;
const y =
((b3 - b4) * (b2 * a1 - b1 * a2) - (b1 - b2) * (b4 * a3 - b3 * a4)) /
-denominator;
return new Point(x, y);
}