mirror of
https://github.com/Pomax/BezierInfo-2.git
synced 2025-08-26 09:44:32 +02:00
curvature
This commit is contained in:
@@ -66,11 +66,17 @@ class BaseAPI {
|
||||
this.parameters = Object.fromEntries(
|
||||
Object.entries(this.dataset)
|
||||
.map((pair) => {
|
||||
let name = pair[0];
|
||||
let v = pair[1];
|
||||
if (v === `null` || v === `undefined`) return [];
|
||||
let d = parseFloat(v);
|
||||
// evaluate "string is number" using == rather than ===
|
||||
return [pair[0], v == d ? d : v];
|
||||
if (v === `true`) return [name, true];
|
||||
else if (v === `false`) return [name, false];
|
||||
else {
|
||||
let d = parseFloat(v);
|
||||
// Use == to evaluate "is this a string number"
|
||||
if (v == d) return [name, d];
|
||||
}
|
||||
return [name, v];
|
||||
})
|
||||
.filter((v) => v.length)
|
||||
);
|
||||
|
@@ -331,29 +331,11 @@ class Bezier {
|
||||
}
|
||||
|
||||
derivative(t) {
|
||||
const mt = 1 - t;
|
||||
let a,
|
||||
b,
|
||||
c = 0,
|
||||
p = this.dpoints[0];
|
||||
if (this.order === 2) {
|
||||
p = [p[0], p[1], ZERO];
|
||||
a = mt;
|
||||
b = t;
|
||||
}
|
||||
if (this.order === 3) {
|
||||
a = mt * mt;
|
||||
b = mt * t * 2;
|
||||
c = t * t;
|
||||
}
|
||||
const ret = {
|
||||
x: a * p[0].x + b * p[1].x + c * p[2].x,
|
||||
y: a * p[0].y + b * p[1].y + c * p[2].y,
|
||||
};
|
||||
if (this._3d) {
|
||||
ret.z = a * p[0].z + b * p[1].z + c * p[2].z;
|
||||
}
|
||||
return ret;
|
||||
return utils.compute(t, this.dpoints[0]);
|
||||
}
|
||||
|
||||
dderivative(t) {
|
||||
return utils.compute(t, this.dpoints[1]);
|
||||
}
|
||||
|
||||
align() {
|
||||
@@ -362,7 +344,7 @@ class Bezier {
|
||||
}
|
||||
|
||||
curvature(t) {
|
||||
return utils.curvature(t, this.points, this._3d);
|
||||
return utils.curvature(t, this.dpoints[0], this.dpoints[1], this._3d);
|
||||
}
|
||||
|
||||
inflections() {
|
||||
|
@@ -647,11 +647,7 @@ const utils = {
|
||||
return [];
|
||||
},
|
||||
|
||||
curvature: function (t, points, _3d, kOnly) {
|
||||
const dpoints = utils.derive(points);
|
||||
const d1 = dpoints[0];
|
||||
const d2 = dpoints[1];
|
||||
|
||||
curvature: function (t, d1, d2, _3d, kOnly) {
|
||||
let num,
|
||||
dnm,
|
||||
adk,
|
||||
@@ -705,8 +701,8 @@ const utils = {
|
||||
if (!kOnly) {
|
||||
// compute k'(t) based on the interval before, and after it,
|
||||
// to at least try to not introduce forward/backward pass bias.
|
||||
const pk = utils.curvature(t - 0.001, points, _3d, true).k;
|
||||
const nk = utils.curvature(t + 0.001, points, _3d, true).k;
|
||||
const pk = utils.curvature(t - 0.001, d1, d2, _3d, true).k;
|
||||
const nk = utils.curvature(t + 0.001, d1, d2, _3d, true).k;
|
||||
dk = (nk - k + (k - pk)) / 2;
|
||||
adk = (abs(nk - k) + abs(k - pk)) / 2;
|
||||
}
|
||||
|
Reference in New Issue
Block a user