DifferentiableNumber Class Template Reference

#include <C:/Work/specialnumbers_svn/NumberLib/NumbersLib/DifferentiableNumber.h>

Inheritance diagram for DifferentiableNumber:

AbstractFilteredNumber< T, 2, maxOrder > UpdateableNumber

List of all members.


Detailed Description

template<class T, unsigned int maxOrder>
class luma::numbers::DifferentiableNumber< T, maxOrder >

A DifferentiableNumber is a number that keeps track of its own derivatives.

These are calculated every time the number's value is set.

\[ y_n = \Delta x_n = \frac{x_n - x_{n-1}}{t_n} \]

The maximum order of differentiation that will be required is set as one of the template parameters. The intitial value with which the DifferentiableNumber is initialised is returned for any differential requested that was not computed for this differentiable number.

For example:

   DifferentiableNumber<3, float> n(0);

   ...
   //set the value a few times
   ...

   float m = n.getValue(4); //m is 0

This class is to be used in simulations. For example, if position was declared as follows:

   Differentiable<2, Vector2> position (Vector2(0, 0));

and the position is updated every frame, then

The advantage of using this class instead of the usual logic is that it saves a lot of code, and related updates are done in one place. Of course there is some overhead involved.

See also:
IntegrableNumber

Definition at line 57 of file DifferentiableNumber.h.


Public Member Functions

 DifferentiableNumber (T initialValue)
 Constructs a new DifferentiableNumber with the initialValue.
void forceValue (T value)
 Force this number to the given value.
getValue (unsigned int order=1) const
 Gets the value of the mth derivative of this DifferentiableNumber.
void setValue (T value, float elapsedTime=1.0f)
 Sets the value for this DifferentiableNumber.

Private Attributes

DifferentiableNumber< T,
maxOrder-1 > 
mDifference
 The difference between the current and previous values is maintained as a DifferentiableNumber<n - 1, T>.
mInitialValue
mPreviousValue
mValue

Constructor & Destructor Documentation

DifferentiableNumber ( initialValue  )  [inline]

Constructs a new DifferentiableNumber with the initialValue.

Note that this should be a form of 0. If T is a Vector2 type, the initialValue should be (0, 0).

Definition at line 126 of file DifferentiableNumber.h.


Member Function Documentation

void forceValue ( value  )  [inline]

Force this number to the given value.

Internal derivative are forced to 0.

Definition at line 117 of file DifferentiableNumber.h.

References DifferentiableNumber::mDifference, DifferentiableNumber::mInitialValue, DifferentiableNumber::mPreviousValue, and DifferentiableNumber::mValue.

Referenced by PIDBufferedNumber::forceValue().

T getValue ( unsigned int  order = 1  )  const [inline, virtual]

Gets the value of the mth derivative of this DifferentiableNumber.

Parameters:
m The order of the derivative for this DifferentiableNumber to get the value of. If m == 0, the current value is returned.

Implements AbstractFilteredNumber< T, 2, maxOrder >.

Definition at line 135 of file DifferentiableNumber.h.

References DifferentiableNumber::mDifference, DifferentiableNumber::mInitialValue, and DifferentiableNumber::mValue.

Referenced by PIDBufferedNumber::getValue().

void setValue ( value,
float  elapsedTime = 1.0f 
) [inline, virtual]

Sets the value for this DifferentiableNumber.

Parameters:
elapsedTime The amount of thime passed since the last update.

Implements UpdateableNumber.

Definition at line 108 of file DifferentiableNumber.h.

References luma::numbers::frameRate, DifferentiableNumber::mDifference, DifferentiableNumber::mPreviousValue, and DifferentiableNumber::mValue.

Referenced by PIDBufferedNumber::setValue().


Member Data Documentation

DifferentiableNumber<T, maxOrder - 1> mDifference [private]

The difference between the current and previous values is maintained as a DifferentiableNumber<n - 1, T>.

It will keep track of its own derivatives.

Definition at line 69 of file DifferentiableNumber.h.

Referenced by DifferentiableNumber< T, 1 >::forceValue(), DifferentiableNumber::forceValue(), DifferentiableNumber< T, 1 >::getValue(), DifferentiableNumber::getValue(), DifferentiableNumber< T, 1 >::setValue(), and DifferentiableNumber::setValue().

T mInitialValue [private]

T mPreviousValue [private]

T mValue [private]


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

Generated on Sun Sep 21 20:49:08 2008 for Numbers by  doxygen 1.5.6