Hi all,
I’m trying to approximate a shape described by a set of 3D points with a smooth interpolant, I’ve settled on a parametric B-Spline.
I’ve got a set of 3D points P_i:
using GeometryBasics
P₁ = Point3(0.0, 0.0, 0.0)
P₂ = Point3(1.0, 1.0, 0.1)
P₃ = Point3(1.0, 1.2, 0.5)
P₄ = Point3(2.0, 0.9, 3.0)
and I’m using Interpolations.jl
to build the interpolant as:
using Interpolations
A = [P₁, P₂, P₃, P₄]
Q = interpolate(A, BSpline(Cubic(Free(OnGrid()))))
Then I’m able to use the interpolation function Q(t), t \in [1,4]
Q(1.5)
However, I’m interested in using this interpolating approximation Q(t) within an optimization problem, by changing the degrees of freedom of the B-Spline until I’ve minimized a functional. As a consequence, I’m looking for the jacobian of a given set of points on the curve w.r.t the degrees of freedom of the B-Spline \partial Q(t)/\partial P_i.
I can get this using FiniteDiff.jl
as:
using FiniteDiff
function interp(P₁, P₂, P₃, P₄, t)
A = [P₁, P₂, P₃, P₄]
itp = interpolate(A, BSpline(Cubic(Free(OnGrid()))))
return itp(t)
end
# dQ(1.5)/dP₁
FiniteDiff.finite_difference_jacobian(x->interp(x, P₂, P₃, P₄, 1.5), P₁)
However I’m struggling a bit to simplify this process and get the analytical derivatives.
Usually, B-Splines are defined using a set of control points P'_i that are different from the interpolating points (knots) P_i:
Q(t) = \sum P'_i N_{i,k}(t).
It may be wise to use these control points as degrees of freedom instead, as the derivatives are simply the basis functions N_{i,k}. Can I retrieve these control points and basis functions using the Interpolations.jl
package? I’ve looked into the documentation but I’m a bit lost by the way interpolations are computed.
I may be on the wrong track here though, I’m not quite sure how to get these derivatives in a easier way.
Thanks!