curvature_comb = function(bezier) {
const curve_cheb = bez3_to_cheb(bezier);
const [x, y] = curve_cheb;
const Dx = diff(x), Dy = diff(y);
const DDx = diff(Dx), DDy = diff(Dy);
return function curvature_comb(p) {
const xp = chebeval(x, p), yp = chebeval(y, p);
const Dxp = chebeval(Dx, p), Dyp = chebeval(Dy, p);
const DDxp = chebeval(DDx, p), DDyp = chebeval(DDy, p);
const Ds_inv = 1 / Math.sqrt(Dxp*Dxp + Dyp*Dyp);
const curvature = (Dxp*DDyp - Dyp*DDxp) * (Ds_inv*Ds_inv*Ds_inv);
const squished_curvature = Ds_inv * curvature_transformation(curvature);
return [xp + squished_curvature * Dyp, yp - squished_curvature * Dxp];
}
}