I would like to calculate a third-degree polynomial that is defined by its function values and derivatives at specified points.
https://en.wikipedia.org/wiki/Cubic_Hermite_spline
I know of scipy's interpolation methods. Specifically
splprep to interpolate a N-dimensional spline and splev to eveluate its derivatives.
Is there a python routine that takes function values f(x) and derivatives f'(x) corresponding to values x and calculates a spline representation that fits the given data.
To give an example:
I have two object positions in space defined by the coordinates x,y,z and I know the velocity x',y',z' of the object at these positions. Can I now interpolate the path that the object takes between the two points over time t. Taking all the given parameters into account.
Extending ev-br's answer, here some sample code that exemplifies the usage of
BPoly.from_derivatives
to interpolate between points in n dimensions with prescribed derivatives.To demonstrate the use of this function, we specify the points and tangents. The example further demonstrates the effect if the "magnitude" of the tangents is changed.
This results in the following plot:
Three things to note:
samples
, as it has been discussed for instance in this post.BPoly.from_derivatives
does not ensure smooth transitions between the splines at this position. If for exampletangents[1]
in the above sample is set toNone
,sampleCubicSplinesWithDerivative(points, tangents, resolution)
, the result will look like this:You can use
BPoly.from_derivatives
. The result is a polynomial in the Bernstein basis.