@thi.ng/vectors
Version:
Optimized 2d/3d/4d and arbitrary length vector operations, support for memory mapping/layouts
42 lines (41 loc) • 994 B
JavaScript
import { HALF_PI, PI } from "@thi.ng/math/api";
import { addmN } from "./addmn.js";
import { direction2 } from "./direction.js";
import { headingXY } from "./heading.js";
import { mixN2 } from "./mixn.js";
import { normalize, normalize2 } from "./normalize.js";
import { perpendicularCCW } from "./perpendicular.js";
import { sub } from "./sub.js";
const bisect2 = (a, b) => {
const theta = (headingXY(a) + headingXY(b)) / 2;
return theta <= HALF_PI ? theta : PI - theta;
};
const cornerBisector = (out, a, b, c, n = 1) => {
!out && (out = []);
return normalize(
out,
addmN(
out,
normalize(out, sub(out, a, b)),
normalize(null, sub([], c, b)),
0.5
),
n
);
};
const cornerBisector2 = (out, a, b, c, n = 1) => {
!out && (out = []);
return perpendicularCCW(
out,
normalize2(
out,
mixN2(out, direction2(out, a, b), direction2([], b, c), 0.5),
n
)
);
};
export {
bisect2,
cornerBisector,
cornerBisector2
};