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

more than one S(t) for curve fitting

This commit is contained in:
Pomax
2018-06-22 18:55:34 -07:00
parent 15f50ae53f
commit 5047e74b4e
8 changed files with 94 additions and 41 deletions

View File

@@ -2371,14 +2371,23 @@ return {
reset: function() {
this.points = [];
this.curveset = false;
let api = this.api;
if (api) {
this.mode = 0;
if (this.api) {
let api = this.api;
api.setCurve(false);
api.reset();
api.redraw();
}
},
toggle: function() {
if (this.api) {
this.mode = (this.mode + 1) % fit.modes.length;
this.fitCurve(this.api);
this.api.redraw();
}
},
draw: function(api, curve) {
api.setPanelCount(1);
api.reset();
@@ -2387,19 +2396,7 @@ return {
api.setColor('black');
if (!this.curveset && this.points.length > 2) {
let bestFitData = fit(this.points),
x = bestFitData.C.x,
y = bestFitData.C.y,
bpoints = [];
x.forEach((r,i) => {
bpoints.push({
x: r[0],
y: y[i][0]
});
});
curve = new api.Bezier(bpoints);
api.setCurve(curve);
this.curveset = true;
this.fitCurve(api);
}
if (curve) {
@@ -2407,6 +2404,25 @@ return {
api.drawSkeleton(curve);
}
api.drawPoints(this.points);
api.setFill(0);
api.text("using "+fit.modes[this.mode]+" t values", {x: 5, y: 10});
},
fitCurve(api) {
let bestFitData = fit(this.points, this.mode),
x = bestFitData.C.x,
y = bestFitData.C.y,
bpoints = [];
x.forEach((r,i) => {
bpoints.push({
x: r[0],
y: y[i][0]
});
});
var curve = new api.Bezier(bpoints);
api.setCurve(curve);
this.curveset = true;
},
onClick: function(evt, api) {