HomeWildfire Games

Extend the cubicInterpolation function to consume a tension argument allowing…

Description

Extend the cubicInterpolation function to consume a tension argument allowing to modulate the smoothness of the interpolation.

Thereby unify the chordal Catmull-Rom spline interpolation of the ClumpPlacer (C++ rP2378, JS rP9096),
the copy of that in the PathPlacer (rP11152, refs #892) and
the centripetal Catmull-Rom spline of the bicubicInterpolation function from rP18925, refs #4218
and don't claim the latter to be a uniform Catmull-Rom spline.

Reviewed in part by fatherbushido, discussed in rP18925.

Details

Committed
elexisOct 30 2017, 9:43 PM
Parents
rP20382: Adds a missed initialisation in rP20378.
Branches
Unknown
Tags
Unknown
Build Status
Buildable 3553
Build 6165: Post-Commit BuildJenkins

Event Timeline

My sources again:
https://www.cs.cmu.edu/~462/projects/assn2/assn2/catmullRom.pdf
https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline#Definition

(I was allowed to state fatherbushidos name in the commit message, but we didn't arrange an exact sentence.)

/ps/trunk/binaries/data/mods/public/globalscripts/interpolation.js
23

(float isn't a JS type)

/ps/trunk/binaries/data/mods/public/maps/random/rmgen/placer_noncentered.js
143

Notice P,Q,R,S are computed outside of the loop. I tested passing an array of points instead of a point to the interpolation function, but the performance is irrelevant here.
The entire path placing on Corsica vs Sardinia consumes 160ms in my test, this mentioned aspect makes it 5ms slower and we have a 0 to a dozen of paths on a map, not tens of thousands.

fatherbushido added inline comments.
/ps/trunk/binaries/data/mods/public/globalscripts/interpolation.js
6

I think "loose" is better than "smooth" here.

7

I think there is a mismatch between two different things here.

elexis added inline comments.Oct 31 2017, 9:50 AM
/ps/trunk/binaries/data/mods/public/globalscripts/interpolation.js
7

being?

fatherbushido added inline comments.Oct 31 2017, 10:12 AM
/ps/trunk/binaries/data/mods/public/globalscripts/interpolation.js
7

Hard to type I have a sys error which fills my /var/log/ :-(
With the notation of your second article, alpha is a parameter used for the parametrisation of control points.
The tension (tau iirc in the first article) is a parameter to scale the two approximated tangents.

We/you/chuck_norris only use(s) uniform case.

elexis added inline comments.Oct 31 2017, 11:47 AM
/ps/trunk/binaries/data/mods/public/globalscripts/interpolation.js
6

(I didn't read loose anywhere but saw few occurrences of curve smoothing, so I chose that. If you have any references, let me know.)

7

It would help if the original paper from 1974 would be available to the public instead of combinging random unrelated secondary work.

So if I understand correctly, both the knot parameterization and tension are typically 0, 0.5 or 1 and determine if its a loose/smooth or tight curve.
(Which means this graphic could be true for both parameters: https://upload.wikimedia.org/wikipedia/commons/2/2f/Catmull-Rom_examples_with_parameters..png )

This https://codeplea.com/introduction-to-splines seems to indicate that this function does not compute Catmull-Rom splines for tension != 0.5:
"A Cardinal spline with a tension of .5 is a special case. It's then called a Catmull-Rom spline."

Somehow I would prefer to just delete the Catmull-Rom spline. and Depending on the tension, sentence intead of helplessly searching random articles for hours if that doesn't result in anything accurate.

(Also approximated != interpolated, I was about to type that too in the JS comments)

elexis added inline comments.Oct 31 2017, 1:31 PM
/ps/trunk/binaries/data/mods/public/globalscripts/interpolation.js
7

Hard to type I have a sys error which fills my /var/log/ :-(

What is it?

fatherbushido added inline comments.Nov 1 2017, 7:57 AM
/ps/trunk/binaries/data/mods/public/globalscripts/interpolation.js
7

It would help if the original paper from 1974 would be available to the public instead of combinging random unrelated secondary work.

Any notes/textbook with clear definitions and proofs is ok.

This https://codeplea.com/introduction-to-splines seems to indicate that this function does not compute Catmull-Rom splines for tension != 0.5:
"A Cardinal spline with a tension of .5 is a special case. It's then called a Catmull-Rom spline."

About naming, you can use what you want, Catmull-Rom, generalized Catmull-Rom, Cardinal (one often use the orginal name even for extended things).

Somehow I would prefer to just delete the Catmull-Rom spline. and Depending on the tension, sentence intead of helplessly searching random > articles for hours if that doesn't result in anything accurate.

Why? There was just a misinterpretation of your two sources in the current comment.

(Also approximated != interpolated, I was about to type that too in the JS comments)

What do you refer too?
If it's about that

two approximated tangents

Here the word approximated refers to the fact that you don't provide the derivative but approximate it with the surrounding control points.

fatherbushido added inline comments.Nov 1 2017, 9:24 AM
/ps/trunk/binaries/data/mods/public/globalscripts/interpolation.js
6

What kind of ref do you want?

If we set 0 tension, you have horizontal tangents.
If we set high tension ~~ you get an electric shock ~~, you have big slopes for the tangents.
The result in the first case is that the interpolation is 'tight', in the other case the interpolation is 'loose' (which also match with the word 'tension').
(Perhaps we could measure that in some norm but that's totally off topic).

Smooth has a precise mathematical meaning and that's not the thing your comment wanted to speak about.

elexis added inline comments.Nov 1 2017, 11:15 AM
/ps/trunk/binaries/data/mods/public/globalscripts/interpolation.js
7

About naming, you can use what you want, Catmull-Rom

If I understand correctly, the interpolation function in our code can compute Catmull-Rom for one tension, but does not compute Catmull-Rom for a different tension, nay?
"Catmull–Rom spline is obtained, being a special case of a cardinal spline" from https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Catmull.E2.80.93Rom_spline

Why delete?

Because I don't have a good source and thus feel unable to determine a good comment without spending one or more days.

Approximation

(we derive a polynomial that goes through the control points (right?) which thus is an interpolation of the points. Approximation usually means we determine a function that comes as close as possible to some given value, but we don't have a target to approximate here. Anyway, OT)

fatherbushido added inline comments.Nov 1 2017, 11:30 AM
/ps/trunk/binaries/data/mods/public/globalscripts/interpolation.js
7
  1. The code last commited can compute Cardinal, generalized Catmul-Rom for any tension. (0.5 is the original value used).
  2. remove that comment which is just a mismatch between two differents things:
  • Depending on the tension, the spline is called uniform (0), centripetal (0.5) or chordal (1).
  1. I dont' know to which word approximation you are refering too. If that's the one I used above, instead of giving 2 values and 2 derivates, we use 2 values and two approximation of the derivates.

but we don't have a target to approximate here.

As you add that, interpolation needs to be a good approximation in the ad hoc distance.

elexis added inline comments.Nov 1 2017, 12:52 PM
/ps/trunk/binaries/data/mods/public/globalscripts/interpolation.js
6

Smooth

You are right, I definitely didn't mean https://en.wikipedia.org/wiki/Smoothness which is an attribute of the polynomial which is independent of the tension.

What kind of ref?

(Just wanted to see if anyone else uses that term, so any article would do/have done.)

The only comments about tension I could find are:

https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Cardinal_spline
"it affects how sharply the curve bends at the (interpolated) control points."

http://www.charlespetzold.com/blog/2009/01/Canonical-Splines-in-WPF-and-Silverlight.html
"the amount of curvature is governed by a tension parameter"

So we could make it:
"The tension is a number between 0 and 1 and determines how sharply the curve bends at the given points".

7

1. Catmull-Rom vs Cardinal spline

generalized Catmul-Rom

(careful)
As far as I (now) see, a Catmull-Rom spline is by definition a cardinal spline with tension zero.
So my JS comment seems wrong.

From https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Cardinal_spline
"Choosing c=1 yields all zero tangents, and choosing c=0 yields a Catmull–Rom spline"

From https://www.gamedev.net/forums/topic/558581-catmull-rom-tension/?tab=comments#comment-4585139
"Catmull Rom splines with Tension are called Cardinal Splines"

So I think the first line of this file should be deleted and a new line should be inserted below the then first sentence:
"Computes a cardinal spline (aka canonical spline). If the tension is zero, computes a (uniform?) Catmull-Rom spline."

(3. Interpolation vs Approximation)

interpolation needs to be a good approximation in the ad hoc distance.

(distance to the existing data points right? But we need that polynomial to run exactly through the existing data points, right? and we don't have any other data points)

(From https://en.wikipedia.org/wiki/Interpolation )

interpolation is a method of constructing new data points within the range of a discrete set of known data points.
A different problem which is closely related to interpolation is the approximation of a complicated function by a simple function.

(At this point it doesn't matter what I refered to :P but yes, the first time that word was mentioned on this URL)

fatherbushido added inline comments.Nov 1 2017, 3:15 PM
/ps/trunk/binaries/data/mods/public/globalscripts/interpolation.js
7

Ah I missed that one.

  1. There are many way to name things, depending of history and so on. Generalized Catmull-Rom splines, Cardinal splines, even Catmul-Rom splines are acceptable names. (For exemple, one often name Pythagorean theorem things on something else that euclid plan).

(canonical is imo confusing).

(uniform?)

In the current function, it's uniform (see comment in the last diff).

interpolation needs to be a good approximation in the ad hoc distance.

(distance to the existing data points right? But we need that polynomial to run exactly through the existing data points, right? and we don't have >any other data points)

(From https://en.wikipedia.org/wiki/Interpolation )

Forget that, what I said is wrong. I had something else in mind :)

(At this point it doesn't matter what I refered to :P but yes, the first time that word was mentioned on this URL)

(so approximation was indeed the good word in that case)

elexis added inline comments.Nov 13 2017, 11:51 PM
/ps/trunk/binaries/data/mods/public/globalscripts/interpolation.js
7

(I wonder if I will ever understand, but maybe I was miseducated on the concept of coincidence)