Page MenuHomeWildfire Games

Correct cubicInterpolation cardinal / Catmull-Rom spline comment
ClosedPublic

Authored by elexis on Nov 1 2017, 1:00 PM.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

elexis created this revision.Nov 1 2017, 1:00 PM
Vulcan added a subscriber: Vulcan.Nov 1 2017, 1:34 PM
Executing section Default...
Executing section Source...
Executing section JS...
Vulcan added a comment.Nov 1 2017, 1:37 PM

Successful build - Chance fights ever on the side of the prudent.

Updating workspaces...
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (307 tests)...................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (307 tests)...................................................................................................................................................................................................................................................................................................................OK!
Checking XML files...
fatherbushido added inline comments.
binaries/data/mods/public/globalscripts/interpolation.js
4 ↗(On Diff #4051)

(one get an original Catmull-Rom spline when the tension is 1/2, but you can even delete that part, 'Computes a cardinal spline' could be enough)

6 ↗(On Diff #4051)

(no real need to clamp the tension)

fatherbushido added a comment.EditedNov 1 2017, 2:16 PM

You can check straightly with the provided function defined by f(x)=((P * x + Q) * x + R) * x + S that:
f(0) = p1
f(1) = p2
df/dx (0) = tension * (p2-p0)
df/dx((1) = tension * (p3-p1)
Then one can understand that for tension = 1/2, the slope in p1 is well given by the slope of the line (p0,p2) and the slope in p2 is well given by the slope of the line (p1, p3), which are the requested things.
(tension 0 is something which should be rarely desirable)

elexis added a comment.Nov 1 2017, 4:40 PM

check

I can confirm your computation, but I need definition of CR to conclude if it's a CR spline. I must resign.
To prevent future interpolation users from adding a redundant function, the words "cardinal spline" and "Catmull-Rom spline" should still appear, but it can be phrased in a meaningless (hence not false) way.

Generalized Catmull-Rom splines, Cardinal splines, even Catmul-Rom splines are acceptable names.

As I never read "generalized CR" anywhere, I think some future reader might want to change that if it were used.

(I took the statement that tension = 0 resluts in the Catmull-Rom spline and that the tension must be in the interval [0, 1] from here.
I guess if it is a mistake, the reason for that would be that the cardinal spline being a special case of the cubic hermite spline does not imply that the tension of the cardinal spline inherits the definition of the cubic hermite spline.)

elexis updated this revision to Diff 4057.Nov 1 2017, 4:42 PM

Don't even try to state something precise about Catmull-Rom splines.

In D1003#39281, @elexis wrote:

(I took the statement that tension = 0 resluts in the Catmull-Rom spline and that the tension must be in the interval [0, 1] from here.
I guess if it is a mistake,

They are also right. But for the m_k they divide by the length of the interval (to get the actual slope). [...]. And finally 1 - 2 * 1/2 = 0.

the reason for that would be that the cardinal spline being a special case of the cubic hermite spline does not imply that the tension of the cardinal spline inherits the definition of the cubic hermite spline.)

In all those cases, tension is a factor for the derivatives. For convenience one can choose T, (1-T) / interval length, (T - 1/2 ) etc...

fatherbushido added inline comments.Nov 1 2017, 4:52 PM
binaries/data/mods/public/globalscripts/interpolation.js
4 ↗(On Diff #4051)

The good point is that the or can be interpreted in many ways.

fatherbushido accepted this revision.Nov 1 2017, 4:52 PM
This revision is now accepted and ready to land.Nov 1 2017, 4:52 PM
Vulcan added a comment.Nov 1 2017, 4:58 PM

Successful build - Chance fights ever on the side of the prudent.

Updating workspaces...
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (307 tests)...................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (307 tests)...................................................................................................................................................................................................................................................................................................................OK!
Checking XML files...
Vulcan added a comment.Nov 1 2017, 5:00 PM
Executing section Default...
Executing section Source...
Executing section JS...
This revision was automatically updated to reflect the committed changes.