Skip to content

Commit

Permalink
feat(geom-splines): add cubicTangentAt / quadraticTangentAt()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Aug 17, 2019
1 parent 4b74159 commit e1cf355
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/geom-splines/src/cubic-tangent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
addW4,
normalize,
ReadonlyVec,
Vec
} from "@thi.ng/vectors";

export const cubicTangentAt = (
out: Vec,
a: ReadonlyVec,
b: ReadonlyVec,
c: ReadonlyVec,
d: ReadonlyVec,
t: number,
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
);
};
2 changes: 2 additions & 0 deletions packages/geom-splines/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ export * from "./cubic-line";
export * from "./cubic-quadratic";
export * from "./cubic-sample";
export * from "./cubic-split";
export * from "./cubic-tangent";

export * from "./quadratic-bounds";
export * from "./quadratic-closest-point";
export * from "./quadratic-line";
export * from "./quadratic-sample";
export * from "./quadratic-split";
export * from "./quadratic-tangent";

export * from "./point-at";
21 changes: 21 additions & 0 deletions packages/geom-splines/src/quadratic-tangent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
addW2,
normalize,
ReadonlyVec,
sub,
Vec
} from "@thi.ng/vectors";

export const quadraticTangentAt = (
out: Vec,
a: ReadonlyVec,
b: ReadonlyVec,
c: ReadonlyVec,
t: number,
len = 1
) =>
normalize(
out,
addW2(out, sub(out, b, a), sub([], c, b), 2 * (1 - t), 2 * t),
len
);

0 comments on commit e1cf355

Please sign in to comment.