Advertisement

Spline interpolation

Started by August 07, 2020 04:06 AM
4 comments, last by HoratioHuffnagel 4 years, 2 months ago

Hi,

I have a problem with regards to spline interpolation for a system that underlies the user input for a brush tool of a paint program. I have a brief to write a module that will take a point and the time since the last point was recorded. It will accumulate those points until such time it has enough to create a spline, and then record x number of “sampled” points based on a step / time value (these points are stored in a buffer to be read separately).

I'm using catmull-rom to calculate the points on the spline (which works fine). But what I am unsure of is exactly how to calculate the arc-length based on time and step to get the sample points I require.

Any thoughts would be appreciated.

Since you have only a few points to process, you should be able to solve for arc length parametrization of your spline iteratively.

If you want to approximate your spline with points that have N short line segments of equal length between them you can start with N-1 guesses of parameter values Ti between a and b (uniform spacing, Ti=a+(b-a)*i/N is a fine initialization), compute the total length L of the curve and the length from the beginning to each point Li (0 and L at the extremes).

Since Li should be L*i/N, you can update the i-th point to new Ti=old Ti*L*i/(Li*N) repeatedly until every Ti changes less than a certain threshold.

Omae Wa Mou Shindeiru

Advertisement

As far as I read in the past it is not possible to compute the arc-length of a cubic spline with a parametric equation. Due to some math it can not be integrated, the exact reason I don't remember. Anyway dividing it into segments and use that as an approximation works. I think around 10 iterations or less should give a decent result

@LorenzoGatti Thanks very much - that is really useful. I wish I was better at maths - but that makes sense. ?

This is the approach I went with in the end - thanks for that. It's not perfect, but accurate enough.

This topic is closed to new replies.

Advertisement