cubic-beziers-through-points
Version:
A function to fit fair (bending energy minimizing) cubic bezier curves through a set of given ordered points in the plane.
38 lines • 1.16 kB
JavaScript
import { getBendingEnergy } from "flo-bezier3";
import { cubicFromAnglesAndSpeeds } from 'flo-bezier3';
/**
* Returns the bending energy of the given curve (within info) with the `α`
* angle replaced with the given one.
*/
function getEα(info) {
return (α) => {
const [_ps, ps_] = getPssByα(α, info);
const e_ = getBendingEnergy(ps_);
const _e = getBendingEnergy(_ps);
return e_ + _e;
};
}
/**
* Returns the points of the given curve (within info) with the `α`
* angle replaced with the given one.
*/
function getPssByα(α, info) {
const { ϕ } = info;
const _info = info._info;
const _$ps = _info.$ps;
const $ps = info.$ps;
const β = α - ϕ;
const _ps = cubicFromAnglesAndSpeeds({ ..._$ps, β, s0: 1, s1: 1 });
const ps = cubicFromAnglesAndSpeeds({ ...$ps, α, s0: 1, s1: 1 });
{
const _ops = _info.ps;
const ops = info.ps;
// preserve identities
return [
[_ops[0], _ps[1], _ps[2], _ops[3]],
[ops[0], ps[1], ps[2], ops[3]],
];
}
}
export { getEα, getPssByα };
//# sourceMappingURL=get-e-alpha.js.map