From 94edb1d24e97838dfe204da8073af4ccfcc22caa Mon Sep 17 00:00:00 2001 From: Sathvik Bhagavan Date: Fri, 17 Nov 2023 08:41:53 +0000 Subject: [PATCH] fix: derivatives of BSplines at t=0 --- src/derivatives.jl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/derivatives.jl b/src/derivatives.jl index fb6a62c2..46671964 100644 --- a/src/derivatives.jl +++ b/src/derivatives.jl @@ -158,8 +158,12 @@ function derivative(A::BSplineInterpolation{<:AbstractVector{<:Number}}, t::Numb t_ = A.p[idx] + (t - A.t[idx]) * scale N = DataInterpolations.spline_coefficients(n, A.d - 1, A.k, t_) ducum = zero(eltype(A.u)) - for i in 1:(n - 1) - ducum += N[i + 1] * (A.c[i + 1] - A.c[i]) / (A.k[i + A.d + 1] - A.k[i + 1]) + if t == A.t[1] + ducum = (A.c[2] - A.c[1]) / (A.k[A.d + 2]) + else + for i in 1:(n - 1) + ducum += N[i + 1] * (A.c[i + 1] - A.c[i]) / (A.k[i + A.d + 1] - A.k[i + 1]) + end end ducum * A.d * scale, idx end @@ -175,8 +179,12 @@ function derivative(A::BSplineApprox{<:AbstractVector{<:Number}}, t::Number, igu t_ = A.p[idx] + (t - A.t[idx]) * scale N = spline_coefficients(A.h, A.d - 1, A.k, t_) ducum = zero(eltype(A.u)) - for i in 1:(A.h - 1) - ducum += N[i + 1] * (A.c[i + 1] - A.c[i]) / (A.k[i + A.d + 1] - A.k[i + 1]) + if t == A.t[1] + ducum = (A.c[2] - A.c[1]) / (A.k[A.d + 2]) + else + for i in 1:(A.h - 1) + ducum += N[i + 1] * (A.c[i + 1] - A.c[i]) / (A.k[i + A.d + 1] - A.k[i + 1]) + end end ducum * A.d * scale, idx end