UNPKG

@thi.ng/geom-splines

Version:

nD cubic & quadratic curve analysis, conversion, interpolation, splitting

17 lines (16 loc) 394 B
import { addW4 } from "@thi.ng/vectors/addw"; import { normalize } from "@thi.ng/vectors/normalize"; const cubicTangentAt = (out, a, b, c, d, t, len = 1) => { const s = 1 - t; const ss = s * s; const tt = t * t; const ts2 = 2 * t * s; return normalize( out, addW4(out, a, b, c, d, -3 * ss, 3 * (ss - ts2), 3 * (ts2 - tt), 3 * tt), len ); }; export { cubicTangentAt };