CARMA C++
carma::util::QuadraticInterpolator Class Reference

The QuadraticInterpolator class is used to perform quadrature interpolation of arbitrary continuous functions, as well as certain periodic functions (angles). More...

#include <carma/util/QuadraticInterpolator.h>

Inheritance diagram for carma::util::QuadraticInterpolator:
carma::util::QuadraticInterpolatorNormal carma::util::QuadraticInterpolatorPositiveAngle carma::util::QuadraticInterpolatorSignedAngle

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...
 
void getXvals (double xVals[3], unsigned *numXvals)
 
double gradient (double x)
 Return the gradient of the function at x. More...
 
void lock ()
 A public method to lock this container. More...
 
void print ()
 
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...
 

Detailed Description

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 59 of file QuadraticInterpolator.h.

Member Enumeration Documentation

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 73 of file QuadraticInterpolator.h.

Constructor & Destructor Documentation

virtual carma::util::QuadraticInterpolator::~QuadraticInterpolator ( )
virtual

Destructor.

carma::util::QuadraticInterpolator::QuadraticInterpolator ( )
protected

Constructor function.

Making this protected prevents instantiation of the base class.

Parameters
emptyValueThe value to return until at least one coordinate pair has been added.
Exceptions
Exception

Member Function Documentation

bool carma::util::QuadraticInterpolator::canBracket ( double  x)

A method to query if the container can bracket the requested value.

void carma::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.

Exceptions
Exception
double carma::util::QuadraticInterpolator::evaluate ( double  x)

Return the value of the function at x.

void carma::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().

Parameters
xdouble The X coordinate of the point to add.
ydouble The Y coordinate of the point to add.
unsigned carma::util::QuadraticInterpolator::getNpt ( )

A method to query the number of points currently in our interpolation container.

double carma::util::QuadraticInterpolator::getXmax ( )

A method to query the maximum x-value in our interpolation container.

double carma::util::QuadraticInterpolator::getXmin ( )

A method to query the minimum x-value in our interpolation container.

double carma::util::QuadraticInterpolator::gradient ( double  x)

Return the gradient of the function at x.

void carma::util::QuadraticInterpolator::lock ( )

A public method to lock this container.

void carma::util::QuadraticInterpolator::setEmptyValue ( double  emptyValue)
protected

A method to set the value to be returned while the interpolation container is empty.

bool carma::util::QuadraticInterpolator::tryLock ( )

A public method to attempt to lock this container.

Returns true if the lock was successful.

void carma::util::QuadraticInterpolator::unlock ( )

A public method to unlock this container.

Member Data Documentation

const double carma::util::QuadraticInterpolator::pi_
static

Define constants.

Definition at line 66 of file QuadraticInterpolator.h.

QuadType carma::util::QuadraticInterpolator::type_
protected

The type of ordinate we are interpolating.

Definition at line 213 of file QuadraticInterpolator.h.


The documentation for this class was generated from the following file: