Ok, here we go. For simplicity I've converted the MEL test from the original post I've mentioned:
CODE
global float $keyframes[] = {
1, 0,
10, 5,
20, 0
};
global string $animName;
global proc runTest()
{
global float $keyframes[];
global string $animName;
// create a new scene
file -f -new;
// create an object
string $group = group -empty
;
// set the animation range
playbackOptions -min 1 -ast 1 -max 20 -aet 20;
$animName = $group + ".ty";
// set 3 keyframes. Make sure default settings of in and out tangents are spline,
// and weighted tangents are turned off.
for($i=0; $i < size($keyframes) / 2; $i++ ) {
setKeyframe -t $keyframes[$i * 2] -v $keyframes[($i * 2)+1] $animName;
}
testBezierCurve (1, $animName);
testBezierCurve (3, $animName);
testBezierCurve (6, $animName);
testBezierCurve (10, $animName);
}
global proc float testBezierCurve (int $keyToTest, string $animName)
{
global float $keyframes[];
// getting the needed tangent values
float $inTangentX [] = keyTangent -q -ix $animName
;
float $inTangentY [] = keyTangent -q -iy $animName
;
float $outTangentX [] = keyTangent -q -ox $animName
;
float $outTangentY [] = keyTangent -q -oy $animName
;
// for simplicity only checking first interval of the curve here (only testing values within this interval)
float $p1X = $keyframes[0];
float $p1Y = $keyframes[1];
float $p4X = $keyframes[1 * 2];
float $p4Y = $keyframes[(1*2) + 1];
// in for the first keyframe
float $n1X = $outTangentX [0];
float $n1Y = $outTangentY [0];
// out for the second keyframe
float $n4X = $inTangentX [1];
float $n4Y = $inTangentY [1];
// MFnAnimCurve docs state that out tangent at P1 is N1 = 3*(P2-P1)
// and in tangent at P4 is N4 = 3*(P4-P3). Hence:
// P2 = N1 / 3 + P1
// P3 = P4 - N4 / 3
float $p2X = ($n1X / 3.0 + $p1X);
float $p2Y = ($n1Y / 3.0 + $p1Y);
float $p3X = $p4X - $n4X / 3.0;
float $p3Y = $p4Y - $n4Y / 3.0;
// normalized time value
float $u = ($keyToTest - $p1X) / ($p4X - $p1X);
float $curveValue = getBezierValue($u, $p1Y, $p2Y, $p3Y, $p4Y);
float $mayaValue = getAttr -t $keyToTest $animName
;
print("Keyframe = " + $keyToTest + "; Maya value = " + $mayaValue + "; Calced value = " + $curveValue + "; Diff. = " + ($mayaValue - $curveValue) + "\n");
return $curveValue;
};
global proc float getBezierValue (float $U, float $P1, float $P2, float $P3, float $P4)
{
float $U2 = $U * $U;
float $U3 = $U2 * $U;
// | -1 3 -3 1 |
// | 3 -6 3 0 |
// | -3 3 0 0 |
// | 1 0 0 0 |
float $H1 = (-1.0 * $U3) + ( 3.0 * $U2) + (-3.0 * $U) + 1.0;
float $H2 = ( 3.0 * $U3) + (-6.0 * $U2) + ( 3.0 * $U) + 0.0;
float $H3 = (-3.0 * $U3) + ( 3.0 * $U2) + ( 0.0 * $U) + 0.0;
float $H4 = ( 1.0 * $U3) + ( 0.0 * $U2) + ( 0.0 * $U) + 0.0;
return ($P1 * $H1) +
($P2 * $H2) +
($P3 * $H3) +
($P4 * $H4);
};
Source it and call runTest()
For visual results this part can be added:
CODE
global proc runTestGeom()
{
global string $animName;
runTest();
int $lastFrame = 10;
for($i=1; $i <= $lastFrame; $i++ ) {
// our vlaue
float $val = testBezierCurve($i, $animName);
// maya value
float $mayaValue = getAttr -t $i $animName
;
spaceLocator -p $i $val 0;
string $sphere[] = sphere -r 0.4
;
setAttr ($sphere[0]+".t") $i $mayaValue 0;
}
}

Spheres are for points produced by maya and locators are for our custom points. It can be seen that the control points are well interpolated, but intermediate values are not exactly the same.
So can you share your code? Or point out whgere the mistake is?
Thank you.