From 076232a67a3d954c22cf72ad0cbec657ea08bd6a Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Tue, 11 Oct 2022 23:44:27 +0530 Subject: [PATCH] [Sketcher] [planegcs] Calculate value at general b-spline --- src/Mod/Sketcher/App/planegcs/Geo.cpp | 14 ++++++++++++++ src/Mod/Sketcher/App/planegcs/Geo.h | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/src/Mod/Sketcher/App/planegcs/Geo.cpp b/src/Mod/Sketcher/App/planegcs/Geo.cpp index acf1442d81..1ed70be814 100644 --- a/src/Mod/Sketcher/App/planegcs/Geo.cpp +++ b/src/Mod/Sketcher/App/planegcs/Geo.cpp @@ -746,6 +746,20 @@ double BSpline::getLinCombFactor(double x, size_t k, size_t i, size_t p) return d[p]; } +double BSpline::splineValue(double x, size_t k, size_t p, VEC_D& d, const VEC_D& flatknots) +{ + for (size_t r = 1; r < p + 1; ++r) { + for (size_t j = p; j > r - 1; --j) { + double alpha = + (x - flatknots[j + k - p]) / + (flatknots[j + 1 + k - r] - flatknots[j + k - p]); + d[j] = (1.0 - alpha) * d[j-1] + alpha * d[j]; + } + } + + return d[p]; +} + void BSpline::setupFlattenedKnots() { flattenedknots.clear(); diff --git a/src/Mod/Sketcher/App/planegcs/Geo.h b/src/Mod/Sketcher/App/planegcs/Geo.h index 8de749312a..0ab64871ef 100644 --- a/src/Mod/Sketcher/App/planegcs/Geo.h +++ b/src/Mod/Sketcher/App/planegcs/Geo.h @@ -308,6 +308,13 @@ namespace GCS inline double getLinCombFactor(double x, size_t k, size_t i) { return getLinCombFactor(x, k, i, degree); } void setupFlattenedKnots(); + /// finds spline(x) for the given parameter and knot/pole vector + /// x is the point at which combination is needed + /// k is the range in `flattenedknots` that contains x + /// p is the degree + /// d is the vector of (relevant) poles (this will be changed) + /// flatknots is the vector of knots + static double splineValue(double x, size_t k, size_t p, VEC_D& d, const VEC_D& flatknots); }; } //namespace GCS