Extract element functions into modules (#207)
This commit is contained in:
16
src/math.ts
16
src/math.ts
@ -36,3 +36,19 @@ export function distanceBetweenPointAndSegment(
|
||||
const dy = y - yy;
|
||||
return Math.hypot(dx, dy);
|
||||
}
|
||||
|
||||
export function rotate(
|
||||
x1: number,
|
||||
y1: number,
|
||||
x2: number,
|
||||
y2: number,
|
||||
angle: number
|
||||
) {
|
||||
// 𝑎′𝑥=(𝑎𝑥−𝑐𝑥)cos𝜃−(𝑎𝑦−𝑐𝑦)sin𝜃+𝑐𝑥
|
||||
// 𝑎′𝑦=(𝑎𝑥−𝑐𝑥)sin𝜃+(𝑎𝑦−𝑐𝑦)cos𝜃+𝑐𝑦.
|
||||
// https://math.stackexchange.com/questions/2204520/how-do-i-rotate-a-line-segment-in-a-specific-point-on-the-line
|
||||
return [
|
||||
(x1 - x2) * Math.cos(angle) - (y1 - y2) * Math.sin(angle) + x2,
|
||||
(x1 - x2) * Math.sin(angle) + (y1 - y2) * Math.cos(angle) + y2
|
||||
];
|
||||
}
|
||||
|
Reference in New Issue
Block a user