CARMA C++
|
The QuadraticInterpolator class is used to perform quadrature interpolation of arbitrary continuous functions, as well as certain periodic functions (angles). More...
#include <carma/szautil/QuadraticInterpolator.h>
Public Types | |
enum | QuadType { QP_NORMAL, QP_SIGNED_ANGLE, QP_POSITIVE_ANGLE } |
Enumerate the various types of ephemeris types we might handle. More... | |
Public Member Functions | |
bool | canBracket (double x) |
A method to query if the container can bracket the requested value. More... | |
void | empty () |
Empty the coordinate table of a QuadraticInterpolator object. More... | |
double | evaluate (double x) |
Return the value of the function at x. More... | |
void | extend (double x, double y) |
Append or prepend an x,y coordinate pair to the three-entry circular table of a quadratic interpolation object. More... | |
unsigned | getNpt () |
A method to query the number of points currently in our interpolation container. More... | |
double | getXmax () |
A method to query the maximum x-value in our interpolation container. More... | |
double | getXmin () |
A method to query the minimum x-value in our interpolation container. More... | |
double | gradient (double x) |
Return the gradient of the function at x. More... | |
void | lock () |
A public method to lock this container. More... | |
bool | tryLock () |
A public method to attempt to lock this container. More... | |
void | unlock () |
A public method to unlock this container. More... | |
virtual | ~QuadraticInterpolator () |
Destructor. More... | |
Static Public Attributes | |
static const double | pi_ |
Define constants. More... | |
static const double | twopi_ |
Protected Member Functions | |
QuadraticInterpolator () | |
Constructor function. More... | |
void | setEmptyValue (double emptyValue) |
A method to set the value to be returned while the interpolation container is empty. More... | |
Protected Attributes | |
QuadType | type_ |
The type of ordinate we are interpolating. More... | |
The QuadraticInterpolator class is used to perform quadrature interpolation of arbitrary continuous functions, as well as certain periodic functions (angles).
This class will store up to three (x,y) pairs of a function to be interpolated, and provide a public interface to return the value and gradient of the function at arbitrary x, through the eval() and grad() methods. The behaviors of these methods under different conditions are described in the documentation below.
The class is initialized with a value to be returned until valid samples of a function have been loaded, as well as the type of function being interpolated.
Samples are loaded using the extend() method (see documentation below). As new samples are installed, they are appended or prepended to an internal circular buffer of samples, according to the x values of the pairs.
At a discontinuity (say, when preparing to interpolate the ephemerides of a new source), the user should discard old samples via the empty() method.
Definition at line 47 of file QuadraticInterpolator.h.
Enumerate the various types of ephemeris types we might handle.
Enumerator | |
---|---|
QP_NORMAL |
A continuous function. |
QP_SIGNED_ANGLE |
Angles defined modulo 2.pi between -pi <= v < pi. |
QP_POSITIVE_ANGLE |
Angles defined modulo 2.pi between 0 <= v < 2.pi. |
Definition at line 61 of file QuadraticInterpolator.h.
|
virtual |
Destructor.
|
protected |
Constructor function.
Making this protected prevents instantiation of the base class.
emptyValue | The value to return until at least one coordinate pair has been added. |
Exception |
bool sza::util::QuadraticInterpolator::canBracket | ( | double | x | ) |
A method to query if the container can bracket the requested value.
void sza::util::QuadraticInterpolator::empty | ( | ) |
Empty the coordinate table of a QuadraticInterpolator object.
After this call the value of the empty_value argument that was presented to QuadraticInterpolator::QuadraticInterpolator() will be returned until extend() is next called.
Exception |
double sza::util::QuadraticInterpolator::evaluate | ( | double | x | ) |
Return the value of the function at x.
void sza::util::QuadraticInterpolator::extend | ( | double | x, |
double | y | ||
) |
Append or prepend an x,y coordinate pair to the three-entry circular table of a quadratic interpolation object.
Entries are kept in ascending order of x, so if the new x value is larger than any currently in the table, it will be appended, and if it is smaller it will be prepended. If there are already three entries in the table the one at the other end of the table will be discarded and the table rotated over it to make room for the new sample.
If the new x value is within the range of x values already covered by the table, the interpolator will be left unchanged.
Each time a new entry is added, the three quadratic polynomial coefficients a,b,c (ie. a.x^2+b.x+c) are recomputed for use by eval().
The coefficients are initialized according to the number of entries in the interpolation table. After just one coordinate pair has been entered via this function, eval() returns its y-value irrespective of the target x-value. After a second point has been added, the coefficients implement linear interpolation of the two coordinate pairs. After 3 or more points have been added, the three coefficients implement a quadratic interpolation of the last three points entered.
Note that calls to this function and set() can be interleaved. In fact this function itself calls set().
x | double The X coordinate of the point to add. |
y | double The Y coordinate of the point to add. |
unsigned sza::util::QuadraticInterpolator::getNpt | ( | ) |
A method to query the number of points currently in our interpolation container.
double sza::util::QuadraticInterpolator::getXmax | ( | ) |
A method to query the maximum x-value in our interpolation container.
double sza::util::QuadraticInterpolator::getXmin | ( | ) |
A method to query the minimum x-value in our interpolation container.
double sza::util::QuadraticInterpolator::gradient | ( | double | x | ) |
Return the gradient of the function at x.
void sza::util::QuadraticInterpolator::lock | ( | ) |
A public method to lock this container.
|
protected |
A method to set the value to be returned while the interpolation container is empty.
bool sza::util::QuadraticInterpolator::tryLock | ( | ) |
A public method to attempt to lock this container.
Returns true if the lock was successful.
void sza::util::QuadraticInterpolator::unlock | ( | ) |
A public method to unlock this container.
|
static |
Define constants.
Definition at line 54 of file QuadraticInterpolator.h.
|
protected |
The type of ordinate we are interpolating.
Definition at line 191 of file QuadraticInterpolator.h.