Java Reference
In-Depth Information
Figure 5-5.
Cubic interpolator
Polynomial Interpolator
The
QuadraticInterpolator
allows the creation of nice, clean curves, while the
CubicInterpolator
can
create curves of more complexity. It follows that the more terms in the function, the more complex the
curve that can be expressed. So creating a function with 4, 5, or even more terms will generate
increasingly interesting curves.
The general term for functions like the quadratic and cubic functions is
polynomial
. While a
quadratic function has a term with a power of 2 and a cubic function has a term with the power of 3, a
polynomial can have the highest power of any value. Specifically, the form the polynomial is:
ax
n
+ bx
n-1
+ cx
n-2
… ix
2
+ jx + k = 0
The implementation of the quadratic and cubic interpolators suggests that an interpolator could be
created that implements any number of terms. The code in Listing 5-7 shows how this is done.