trace2 = {
const trace = [];
const traceId = "trace2";
function dist(a, b) {
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
}
function guess(t1, r1, r3) {
const r2 = (r1 + r3) / 2;
const t2 = bezier(r2),
t3 = bezier(r3);
const d2 = dist(t1, t2),
d3 = dist(t1, t3);
if (Math.abs(d3 - speed) < eps) return r3;
if (Math.abs(d2 - speed) < eps) return r2;
if (d2 < speed) return guess(t1, r2, r3);
if (d2 > speed) return guess(t1, r1, r2);
}
var r, t, time;
r = 0;
time = 0;
t = bezier(r);
trace.push(Object.assign(t, { time, r: 0, traceId }));
for (let i = 1; i < n + 1; i++) {
r = guess(trace[i - 1], r, r + 0.1);
t = bezier(r);
time = i / n;
trace.push(
Object.assign(t, { time, r: r, traceId })
);
}
return computeSpeed(trace);
}