fix(curves): connect_curve 真 Hermite 端点条件(G1/G2/G3)
Build & Test / build-and-test (push) Canceled after 0s
VDE Build & Test / build-and-test (push) Canceled after 0s
Build & Test / python-bindings (push) Canceled after 0s

旧实现只匹配位置与归一化切向,内部极点按弦线性摆放(注释自认
Simplified approach),G2/G3 名不副实——continuity_type 对其 G3
过渡曲线只能判到 G2。

改为在两端精确匹配邻居的参数化导数 d1..dk(k=1/2/3 对应度
3/5/7 Bézier),由 Bézier 端点导数三角方程组逐端解出全部极点:
参数 C3 连接使切向、曲率向量、曲率变化率(判级器 G3 口径
((d1×d3)×d1)/|d1|^5)在接缝处全部精确一致。

来源:ViewDesign 集成侧批次 AT(GA-3.4 端点连续性读数)单测
VdeCurveContinuity.ConnectCurveG3GradesG3 暴露;修复后 G1/G3
判级用例全绿。
This commit is contained in:
hm
2026-10-02 21:47:55 +08:00
parent f3b36cb535
commit 6451429df7
+37 -61
View File
@@ -286,14 +286,6 @@ NurbsCurve connect_curve(
Point3D P0 = c1.evaluate(dom1.second); // end of c1
Point3D Pn = c2.evaluate(dom2.first); // start of c2
// Get derivatives at endpoints
Vector3D T1 = c1.derivative(dom1.second, 1); // c1 tangent at end
Vector3D T2 = c2.derivative(dom2.first, 1); // c2 tangent at start
// Normalize tangents
if (T1.norm() > 1e-12) T1 = T1.normalized();
if (T2.norm() > 1e-12) T2 = T2.normalized();
// Determine connection curve degree based on continuity
int degree = 3; // default G1
switch (continuity) {
@@ -302,65 +294,49 @@ NurbsCurve connect_curve(
case Continuity::G3: degree = 7; break;
}
// Build a Bézier transition curve with Hermite end conditions
int n_cp = degree + 1;
std::vector<Point3D> cp(n_cp);
cp[0] = P0;
cp[degree] = Pn;
// Chord length for scaling
double L = (Pn - P0).norm();
if (L < 1e-12) {
// Degenerate: return a straight line
// Degenerate chord: no room for a transition
if ((Pn - P0).norm() < 1e-12) {
return NurbsCurve({P0, Pn}, {0, 0, 1, 1}, {1, 1}, 1);
}
// Scale tangents: typical cubic Hermite uses L/3 for inner controls
double s = L / degree;
// Build a Bézier transition curve with true Hermite end conditions:
// the endpoint derivatives d1..dk (k = 1/2/3 for G1/G2/G3) equal the
// neighbours'. Matching the parametric derivatives makes every
// geometric invariant the continuity grader checks — tangent
// direction, curvature vector, curvature variation — agree exactly.
const Vector3D d1a = c1.derivative(dom1.second, 1);
const Vector3D d2a = (degree >= 5) ? c1.derivative(dom1.second, 2)
: Vector3D::Zero();
const Vector3D d3a = (degree >= 7) ? c1.derivative(dom1.second, 3)
: Vector3D::Zero();
const Vector3D d1b = c2.derivative(dom2.first, 1);
const Vector3D d2b = (degree >= 5) ? c2.derivative(dom2.first, 2)
: Vector3D::Zero();
const Vector3D d3b = (degree >= 7) ? c2.derivative(dom2.first, 3)
: Vector3D::Zero();
// G1: match tangents (P1, P_{n-1})
cp[1] = Point3D(P0 + T1 * s);
const int n_cp = degree + 1;
std::vector<Point3D> cp(n_cp);
// Bézier endpoint derivatives (n = degree):
// C'(0) = n·(B1 - B0)
// C''(0) = n(n-1)·(B2 - 2·B1 + B0)
// C'''(0) = n(n-1)(n-2)·(B3 - 3·B2 + 3·B1 - B0)
// mirrored at t = 1. Solve the triangular systems from each end.
cp[0] = P0;
cp[degree] = Pn;
cp[1] = Point3D(cp[0] + d1a / degree);
cp[degree - 1] = Point3D(cp[degree] - d1b / degree);
if (degree >= 5) {
// G2: match curvature — use second derivatives
Vector3D D2_1 = c1.derivative(dom1.second, 2);
Vector3D D2_2 = c2.derivative(dom2.first, 2);
// For a cubic Bézier: P2 = P0 + 2*s*T1 + s²*κ*N1
// For degree 5: distribute the curvature constraint
// Simplified approach: use the chord line as default, adjust with tangent
cp[degree - 1] = Point3D(Pn - T2 * s);
// Place interior control points along the chord for smoothness
if (degree >= 7) {
// G3: match torsion
double t_step = 1.0 / degree;
for (int i = 2; i < degree - 1; ++i) {
double t = i * t_step;
// Simple linear interpolation for interior controls
cp[i] = Point3D(P0 * (1 - t) + Pn * t);
// Blend tangents near ends
if (i == 2) {
Vector3D mid = P0 * 0.6 + Pn * 0.4;
cp[i] = Point3D(mid + T1 * s * 0.2);
} else if (i == degree - 2) {
Vector3D mid = P0 * 0.4 + Pn * 0.6;
cp[i] = Point3D(mid - T2 * s * 0.2);
}
}
} else {
// Degree 5: fill interior with linear blend
for (int i = 2; i < degree - 1; ++i) {
double t = static_cast<double>(i) / degree;
cp[i] = Point3D(P0 * (1 - t) + Pn * t);
}
}
} else {
// Degree 3: remaining control point is mid with tangent influence
cp[degree - 1] = Point3D(Pn - T2 * s);
// Interior point (if degree > 3) — not applicable for cubic
const double s2 = double(degree) * (degree - 1);
cp[2] = Point3D(2.0 * cp[1] - cp[0] + d2a / s2);
cp[degree - 2] = Point3D(2.0 * cp[degree - 1] - cp[degree] + d2b / s2);
}
if (degree >= 7) {
const double s3 = double(degree) * (degree - 1) * (degree - 2);
cp[3] = Point3D(3.0 * cp[2] - 3.0 * cp[1] + cp[0] + d3a / s3);
cp[degree - 3] = Point3D(cp[degree] - 3.0 * cp[degree - 1]
+ 3.0 * cp[degree - 2] - d3b / s3);
}
// Build clamped knot vector