public class TrapezoidInterpolator extends Interpolator
Vona's utils: a trapezoid interpolator.
This extends Interpolator to follow trapezoid trajectories.
The trajectory may be specified in two ways:
Interpolator.duration and accelFraction, the
fraction of that time that should be spent ramping up at start and down at
endmaxSpeed(vona.time.Clock, double, double, double, double) to use for the constant-speed section and
a accelFractionThe various parameters are related to each other according to the following equations:
maxVelocity = accel*accelFraction*duration distance = accel*(accelFraction*duration)^2 + (1-2*accelFraction)*duration*maxVelocity
Copyright (C) 2004 Marsette A. Vona, III
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
| Modifier and Type | Field and Description |
|---|---|
double |
accel
The acceleration during ramp up/down.
|
double |
accelDistance
Distance traveled accelerating.
|
double |
accelFraction
Fraction in [0.0 0.5) to spend accelerating at the start and
decelerating at the end (constant speed fraction is
1.0-2.0*
accelFraction). |
double |
accelTime
Time spent accelerating.
|
(package private) static java.lang.String |
cvsid
CVS id.
|
static double |
DEFAULT_ACCEL_FRACTION
Default accel fraction.
|
double |
maxVelocity
The velocity during the constant-speed phase.
|
| Constructor and Description |
|---|
TrapezoidInterpolator(Clock clock,
double start,
double end,
double duration)
Covers TrapezoidInterpolator(Clock, double, double, double,
double) but always uses DEFAULT_ACCEL_FRACTION.
|
TrapezoidInterpolator(Clock clock,
double start,
double end,
double duration,
double accelFraction)
Create a new TrapezoidInterpolator.
|
TrapezoidInterpolator(double start,
double end,
double duration)
Covers TrapezoidInterpolator(Clock, double, double, double)
but always uses Interpolator.wallClock.
|
TrapezoidInterpolator(double start,
double end,
double duration,
double accelFraction)
Covers TrapezoidInterpolator(Clock, double, double, double,
double) but always uses Interpolator.wallClock.
|
| Modifier and Type | Method and Description |
|---|---|
protected double |
currentValue(double when)
Hook for subclasses to implement different interpolation schemes.
|
static TrapezoidInterpolator |
fixedDuration(Clock clock,
double start,
double end,
double duration)
Factory method to make a fixed-duration TrapezoidInterpolator.
|
static TrapezoidInterpolator |
fixedDuration(Clock clock,
double start,
double end,
double duration,
double accelFraction)
Factory method to make a fixed-duration TrapezoidInterpolator.
|
static TrapezoidInterpolator |
fixedDuration(double start,
double end,
double duration)
Factory method to make a fixed-duration TrapezoidInterpolator.
|
static TrapezoidInterpolator |
fixedDuration(double start,
double end,
double duration,
double accelFraction)
Factory method to make a fixed-duration TrapezoidInterpolator.
|
static double |
getDuration(double start,
double end,
double maxSpeed)
Covers
getDuration(double, double, double, double) but always
uses DEFAULT_ACCEL_FRACTION. |
static double |
getDuration(double start,
double end,
double maxSpeed,
double accelFraction)
Compute a duration given
maxSpeed(vona.time.Clock, double, double, double, double) and accelFraction. |
static TrapezoidInterpolator |
maxSpeed(Clock clock,
double start,
double end,
double maxSpeed)
Factory method to make a maximum speed TrapezoidInterpolator.
|
static TrapezoidInterpolator |
maxSpeed(Clock clock,
double start,
double end,
double maxSpeed,
double accelFraction)
Factory method to make a maximum speed TrapezoidInterpolator.
|
static TrapezoidInterpolator |
maxSpeed(double start,
double end,
double maxSpeed)
Factory method to make a maximum speed TrapezoidInterpolator.
|
static TrapezoidInterpolator |
maxSpeed(double start,
double end,
double maxSpeed,
double accelFraction)
Factory method to make a maximum speed TrapezoidInterpolator.
|
currentValue, resetpublic static final double DEFAULT_ACCEL_FRACTION
Default accel fraction.
static final java.lang.String cvsid
CVS id.
public final double accelFraction
Fraction in [0.0 0.5) to spend accelerating at the start and
decelerating at the end (constant speed fraction is
1.0-2.0*accelFraction).
public final double accel
The acceleration during ramp up/down.
public final double maxVelocity
The velocity during the constant-speed phase.
public final double accelTime
Time spent accelerating.
public final double accelDistance
Distance traveled accelerating.
public TrapezoidInterpolator(Clock clock, double start, double end, double duration, double accelFraction)
Create a new TrapezoidInterpolator.
clock - the time base, if null then use Interpolator.wallClockstart - the initial valueend - the final falueduration - the duration in seconds according to clockaccelFraction - a fraction in [0.0 0.5) to spend accelerating at the
start and decelerating at the end (constant speed fraction is
1.0-2.0*accelFraction)public TrapezoidInterpolator(double start,
double end,
double duration,
double accelFraction)
Covers TrapezoidInterpolator(Clock, double, double, double,
double) but always uses Interpolator.wallClock.
public TrapezoidInterpolator(Clock clock, double start, double end, double duration)
Covers TrapezoidInterpolator(Clock, double, double, double,
double) but always uses DEFAULT_ACCEL_FRACTION.
public TrapezoidInterpolator(double start,
double end,
double duration)
Covers TrapezoidInterpolator(Clock, double, double, double)
but always uses Interpolator.wallClock.
public static double getDuration(double start,
double end,
double maxSpeed,
double accelFraction)
Compute a duration given maxSpeed(vona.time.Clock, double, double, double, double) and accelFraction.
start - the initial valueend - the final falueaccelFraction - a fraction in [0.0 0.5) to spend accelerating at the
start and decelerating at the end (constant speed fraction is
1.0-2.0*accelFraction)public static double getDuration(double start,
double end,
double maxSpeed)
Covers getDuration(double, double, double, double) but always
uses DEFAULT_ACCEL_FRACTION.
public static TrapezoidInterpolator fixedDuration(Clock clock, double start, double end, double duration, double accelFraction)
Factory method to make a fixed-duration TrapezoidInterpolator.
Covers TrapezoidInterpolator(Clock, double, double, double,
double).
public static TrapezoidInterpolator fixedDuration(double start, double end, double duration, double accelFraction)
Factory method to make a fixed-duration TrapezoidInterpolator.
Covers fixedDuration(Clock, double, double, double, double)
but always uses Interpolator.wallClock.
public static TrapezoidInterpolator fixedDuration(Clock clock, double start, double end, double duration)
Factory method to make a fixed-duration TrapezoidInterpolator.
Covers TrapezoidInterpolator(Clock, double, double,
double).
public static TrapezoidInterpolator fixedDuration(double start, double end, double duration)
Factory method to make a fixed-duration TrapezoidInterpolator.
Covers fixedDuration(Clock, double, double, double)
but always uses Interpolator.wallClock.
public static TrapezoidInterpolator maxSpeed(Clock clock, double start, double end, double maxSpeed, double accelFraction)
Factory method to make a maximum speed TrapezoidInterpolator.
Covers TrapezoidInterpolator(Clock, double, double, double,
double) but computes duration with getDuration(double, double, double, double).
public static TrapezoidInterpolator maxSpeed(double start, double end, double maxSpeed, double accelFraction)
Factory method to make a maximum speed TrapezoidInterpolator.
Covers maxSpeed(Clock, double, double, double, double)
but always uses Interpolator.wallClock.
public static TrapezoidInterpolator maxSpeed(Clock clock, double start, double end, double maxSpeed)
Factory method to make a maximum speed TrapezoidInterpolator.
Covers TrapezoidInterpolator(Clock, double, double, double)
but computes duration with getDuration(double, double, double, double).
public static TrapezoidInterpolator maxSpeed(double start, double end, double maxSpeed)
Factory method to make a maximum speed TrapezoidInterpolator.
Covers maxSpeed(Clock, double, double, double)
but always uses Interpolator.wallClock.
protected double currentValue(double when)
Hook for subclasses to implement different interpolation schemes.
Interpolator.currentValue() calls this to compute intermediate values
between Interpolator.start and Interpolator.end.
This impl computes the trapezoid.
For when < accelTime computes ramp-up at accel.
Otherwise, for when < duration-accelTime computes
const-ant-speed.
Otherwise computes ramp-down.
currentValue in class Interpolatorwhen - the time in seconds according to Interpolator.clock since the
start of the interpolationwhen