@Immutable public final class SplineInterpolator extends java.lang.Object implements Interpolator
For more information on how splines are used to interpolate, refer to the SMIL specification at http://w3c.org.
Instances of this class contain no mutable state and can be safely shared. In fact, due to the non-trivial setup and memory use of this implementation, instance sharing is recommended. This class is thread-safe.
Constructor and Description |
---|
SplineInterpolator(double x1,
double y1,
double x2,
double y2)
Creates a new instance of SplineInterpolator with the control points
defined by (x1,y1) and (x2,y2).
|
Modifier and Type | Method and Description |
---|---|
double |
interpolate(double fraction)
Given a fraction of time along the spline (which we can interpret as the
length along a spline), return the interpolated value of the spline.
|
java.lang.String |
toString() |
@Unique(value="return") public SplineInterpolator(double x1, double y1, double x2, double y2)
x1
- the x value of the first control point.y1
- the y value of the first control point.x2
- the x value of the second control point.y2
- the y value of the second control point.java.lang.IllegalArgumentException
- This exception is thrown when values beyond the allowed [0,1]
range are passed in.@RegionEffects(value="reads All") public double interpolate(double fraction)
We first calculate the t value for the length by doing a lookup in our array of previously calculated values and then linearly interpolating between the nearest values. Then we calculate the Y value for this t.
interpolate
in interface Interpolator
fraction
- a value between 0 and 1, representing the elapsed fraction of a
time interval.public java.lang.String toString()
toString
in class java.lang.Object