1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-08-18 14:31:24 +02:00
Files
BezierInfo-2/docs/chapters/arclength/arclength.js
2020-09-19 18:34:03 -07:00

33 lines
665 B
JavaScript

import { C, T } from "./ct-values.js";
setup() {
this.curve = Bezier.defaultCubic(this);
setMovable(this.curve.points);
}
draw() {
clear();
const curve = this.curve;
curve.drawSkeleton();
curve.drawCurve();
curve.drawPoints();
const len = this.computeLength(curve);
setFill("black");
text(`Curve length: ${len.toFixed(2)} pixels`, 10, 15);
}
computeLength(curve) {
const z = 0.5, len = T.length;
let sum = 0;
for (let i = 0, t; i < len; i++) {
t = z * T[i] + z;
sum += C[i] * this.arcfn(t, curve.derivative(t));
}
return z * sum;
}
arcfn(t, d) {
return sqrt(d.x * d.x + d.y * d.y);
}