plotters icon indicating copy to clipboard operation
plotters copied to clipboard

Option to use cubic spline interpolation instead of linear splines

Open richardlett opened this issue 5 years ago • 9 comments

What is the feature ?

It appears that interpolating between points currently uses linear splines. Using free cubic splines could give smoother looking plots.

(Optional) Why this feature is useful and how people would use the feature ?

I think they look nicer. Free splines often more representative for functions which are continuous. If I remember, correctly, if X is the max of the second derivative on the interval, then linear splines have max error |X|h^2/8, where h is the distance between points.

I'm not sure how they arrived at it, but this document says cubic splines has the error |X| * 5/384*h^4, where X is the max of the fourth derivative on the interval

Here's a comparison of linear vs cubic for a sine function.

image

  • Here is an algorithm for natural cubic splines.

I would be happy to take this issue.

richardlett avatar Jul 26 '20 04:07 richardlett

Hi there, thanks for the suggestion. This is planned for a long time, and I am going to visit it soon, hopefully we will get it with the next major release. - Cheers

38 avatar Aug 28 '20 23:08 38

If someone starts working on this, I would suggest to include Constraint Cubic Splines, too, since they provide curves which look similar smooth (though mathematically they aren't, since they are not everywhere differentiable), but avoid the overshooting problem of Standard Cubic Splines, see e.g. here: constraint cubic spline

xemwebe avatar Oct 09 '22 12:10 xemwebe

I'm really interested in this feature as well.

GyulyVGC avatar Feb 11 '24 21:02 GyulyVGC

@AaronErhardt is it acceptable to implement this feature using a dependency like this one?

In case it is, I can give it a try.

GyulyVGC avatar Feb 11 '24 22:02 GyulyVGC

@AaronErhardt is it acceptable to implement this feature using a dependency like this one?

Yes, but it's probably better to add a feature flag then so that the spline dependency is only compiled when needed.

AaronErhardt avatar Feb 14 '24 13:02 AaronErhardt

Yes, but it's probably better to add a feature flag then so that the spline dependency is only compiled when needed.

Yeah, that's what I was thinking about as well. I'll give it a try when I have some available time then.

GyulyVGC avatar Feb 14 '24 13:02 GyulyVGC

Update: for my use case, I've solved by just building the spline myself and passing a sampled spline as vector of points to plotters. This way I can accurately choose where to sample it and with which frequency, the interpolation type and so on. So in the end, I think there is actually no strict need to include this feature in plotters itself.

GyulyVGC avatar Feb 18 '24 23:02 GyulyVGC

I would definitely use this feature if implemented. :D

Houski avatar Apr 22 '24 16:04 Houski