1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-08-30 03:30:34 +02:00

this rename is absolutely stupid

This commit is contained in:
Pomax
2020-08-20 13:01:32 -07:00
parent 59fdafb2c5
commit d92e370bd1
470 changed files with 22 additions and 9 deletions

View File

@@ -0,0 +1,62 @@
setup() {
const curve = this.curve = new Bezier(this, 70,250, 120,15, 20,95, 225,80);
setMovable(curve.points);
}
draw() {
clear();
const curve = this.curve;
curve.drawSkeleton();
curve.drawCurve();
curve.drawPoints();
const p = curve.align().points,
a = p[2].x * p[1].y,
b = p[3].x * p[1].y,
c = p[1].x * p[2].y,
d = p[3].x * p[2].y,
x = -3*a + 2*b + 3*c - d,
y = 3*a - b - 3*c,
z = c - a,
roots = [];
if (this.almost(x, 0) ) {
if (!this.almost(y, 0) ) {
roots.push(-z / y);
}
}
else {
const det = y * y - 4 * x * z,
sq = sqrt(det),
d2 = 2 * x;
if (!this.almost(d2, 0) ) {
roots.push(-(y+sq) / d2);
roots.push((sq-y) / d2);
}
}
setStroke(`red`);
setFill(`red`);
roots.forEach(t => {
if (0 <= t && t <= 1) {
let p = curve.get(t);
circle(p.x, p.y, 3);
text(`t=${t.toFixed(2)}`, p.x + 5, p.y + 15);
}
});
}
almost(v1, v2, epsilon=0.00001) {
return abs(v1 - v2) < epsilon;
}
onMouseMove() {
redraw();
}