Java Reference
In-Depth Information
Again, after applying the constraints imposed by implementing an interpolator, the function can be
thought of as:
ax 3 + bx 2 + cx = 1
The code in Listing 5-6 implements an interpolator based on the cubic function.
Listing 5-6. CubicInterpolator.fx
public class CubicInterpolator extends SimpleInterpolator {
public var a = 1.0 on replace{
c = 1.0 - a -b;
}
public var b = 1.0 on replace{
c = 1.0 - a -b;
}
var c:Number = 1.0 - a -b;
public override function curve(fraction:Number):Number{
return (a*fraction*fraction*fraction + b*fraction*fraction + c*fraction);
}
}
The implementation of the CubicInterpolator in Listing 5-6 looks a lot like the
QuadraticInterpolator —the coefficients a and b can be set, while the coefficient c is solved for. The
function curve simply adds up the terms. A cubic function was used to produce the curve in Figure 5-5,
which shows the signature up and down wave pattern that identifies a cubic function.
Search WWH ::




Custom Search