Skip to content

Commit a20b16e

Browse files
authored
fix: 修复cr曲线卡死问题 (#386)
2 parents ee41642 + 85fc38c commit a20b16e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

app/src/core/dataStruct/shape/CublicCatmullRomSpline.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ export class CublicCatmullRomSpline extends Shape {
2929
const maxLength = 5; //每一小段的最大长度
3030
let num = 1;
3131
for (; s / num > maxLength; num++);
32+
// console.log("Curve segments: " + num);
3233
for (let i = 0, t0 = 0; i < num - 1; i++) {
3334
for (let left = t0, right = 1; ; ) {
3435
const t = left + (right - left) / 2;
3536
const point = funcs.equation(t);
36-
const requiredError = 0.5;
37+
const requiredError = 0.25;
3738
const dist = point.distance(result[result.length - 1]);
39+
// const dist =
40+
// (t - t0) * NumericalIntegration.romberg((x) => funcs.derivative(x * (t - t0) + t0).magnitude(), 0.1);
3841
const diff = dist - s / num;
42+
// console.log("segment " + (i + 1) + "/" + num + " diff: " + diff);
3943
if (Math.abs(diff) < requiredError) {
4044
result.push(point);
4145
t0 = t;
@@ -45,7 +49,9 @@ export class CublicCatmullRomSpline extends Shape {
4549
} else {
4650
right = t;
4751
}
52+
// console.log("segment " + (i + 1) + "/" + num + " t: " + t);
4853
}
54+
// console.log("segment " + (i + 1) + " compelete");
4955
}
5056
result.push(funcs.equation(1));
5157
}

docs-pg/CublicCatmullRomSpline.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,13 @@ $$
5050
$$
5151
s=\int_0^1 \lvert {\boldsymbol{p}}^{'} \rvert dt
5252
$$
53+
54+
$$
55+
s(t_0, t_1) = \int_{t_0}^{t_1} \lvert {\boldsymbol{p}}^{'} \rvert dt = (t_1-t_0) \int_0^1 \lvert {\boldsymbol{p}}^{'}(x(t_1-t_0)+t_0)\rvert dx
56+
$$
57+
58+
其中
59+
60+
$$
61+
x = \frac{t-t_0}{t_1-t_0}
62+
$$

0 commit comments

Comments
 (0)