Skip to main content
GameDev.net gamedev.net
🔒 Locked

Spline interpolation

Started by HoratioHuffnagel Aug 7, 2020 at 4:06 AM 4 replies 7.3k views
Original Post
HoratioHuffnagel
HoratioHuffnagel

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.

LorenzoGatti
LorenzoGatti

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
51mon
51mon

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

HoratioHuffnagel
HoratioHuffnagel

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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.