Motive Animation System
An open source project by FPL.
 All Classes Functions Variables Typedefs Friends Pages
motive::QuadraticCurve Class Reference

Represent a quadratic polynomial in the form c_[2] * x^2 + c_[1] * x + c_[0]. More...

#include <curve.h>

Detailed Description

Represent a quadratic polynomial in the form c_[2] * x^2 + c_[1] * x + c_[0].

Public Types

typedef Range::TArray< 2 > RootsArray
 
typedef Range::RangeArray< 2 > RangeArray
 

Public Member Functions

 QuadraticCurve (const float c2, const float c1, const float c0)
 
 QuadraticCurve (const float *c)
 
 QuadraticCurve (const QuadraticCurve &q, const float y_scale)
 
 QuadraticCurve (const QuadraticInitWithStartDerivative &init)
 
 QuadraticCurve (const QuadraticInitWithOrigin &init)
 
 QuadraticCurve (const QuadraticInitWithPoint &init)
 
void Init (const QuadraticInitWithStartDerivative &init)
 
void Init (const QuadraticInitWithOrigin &init)
 
void Init (const QuadraticInitWithPoint &init)
 
QuadraticCurveoperator+= (const QuadraticCurve &rhs)
 Add the coefficients of another quadratic curve to this one.
 
QuadraticCurveoperator-= (const QuadraticCurve &rhs)
 Subtract the coefficients of another quadratic curve from this one.
 
void ShiftLeft (const float x_shift)
 
void ShiftRight (const float x_shift)
 Shift the curve along the x-axis: x_shift to the right.
 
void ShiftUp (const float y_offset)
 Shift the curve along the y-axis by y_offset: y_offset up the y-axis.
 
void ScaleUp (const float y_scale)
 Scale the curve along the y-axis by a factor of y_scale.
 
float Evaluate (const float x) const
 
float Derivative (const float x) const
 
float SecondDerivative () const
 
float SecondDerivative (const float) const
 
float ThirdDerivative (const float x) const
 
float EpsilonInRange (const float max_x) const
 
float EpsilonOfCoefficients () const
 
float Epsilon (const float x) const
 
float MaxCoeff () const
 
float Discriminant () const
 
float ReliableDiscriminant (const float epsilon) const
 
float CriticalPoint () const
 Return the x at which the derivative is zero. More...
 
void Roots (RootsArray *roots) const
 
void RootsWithoutNormalizing (RootsArray *roots) const
 
void RootsInRange (const Range &x_limits, RootsArray *roots) const
 
void XsForValue (float value, RootsArray *roots) const
 Calculate the x-coordinates at the value.
 
void RangesMatchingSign (const Range &x_limits, const float sign, RangeArray *matching) const
 
void RangesAboveZero (const Range &x_limits, RangeArray *matching) const
 Return the ranges on which the quadratic is above zero.
 
void RangesBelowZero (const Range &x_limits, RangeArray *matching) const
 Return the ranges on which the quadratic is below zero.
 
float Coeff (int i) const
 Returns the coefficient for x-to-the-ith -power.
 
int NumCoeff () const
 Returns the number of coefficients in this curve.
 
QuadraticCurve ScaleInX (const float x_scale) const
 
QuadraticCurve ScaleInXByReciprocal (const float x_scale_reciprocal) const
 
QuadraticCurve ScaleInY (const float y_scale) const
 Returns the curve y_scale * f(x).
 
QuadraticCurve AbsCoeff () const
 
bool operator== (const QuadraticCurve &rhs) const
 Equality. Checks for exact match. Useful for testing.
 
bool operator!= (const QuadraticCurve &rhs) const
 
std::string Text () const
 A string with the equation for this quadratic. Useful for debugging.
 

Static Public Attributes

static const int kNumCoeff = 3
 

Member Function Documentation

QuadraticCurve motive::QuadraticCurve::AbsCoeff ( ) const
inline

Returns the same curve but with all coefficients in absolute value. Useful for numerical precision work.

float motive::QuadraticCurve::CriticalPoint ( ) const
inline

Return the x at which the derivative is zero.

0 = f'(x) = 2*c2*x + c1 ==> x = -c1 / 2c2

float motive::QuadraticCurve::Derivative ( const float  x) const
inline

Return the quadratic function's slope at x. f'(x) = 2*c2*x + c1

float motive::QuadraticCurve::Discriminant ( ) const
inline

Used for finding roots, and more. See http://en.wikipedia.org/wiki/Discriminant

float motive::QuadraticCurve::Epsilon ( const float  x) const
inline

Given values in the range of x, returns a value below which should be considered zero.

float motive::QuadraticCurve::EpsilonInRange ( const float  max_x) const
inline

Returns a value below which floating point precision is unreliable. If we're testing for zero, for instance, we should test against this value. Pass in the x-range as well, in case that coefficient dominates the others.

float motive::QuadraticCurve::EpsilonOfCoefficients ( ) const
inline

Returns a value below which floating point precision is unreliable. If we're testing for zero, for instance, we should test against this value. We don't consider the x-range here, so this value is useful only when dealing with the equation itself.

float motive::QuadraticCurve::Evaluate ( const float  x) const
inline

Return the quadratic function's value at x. f(x) = c2*x^2 + c1*x + c0

float motive::QuadraticCurve::MaxCoeff ( ) const
inline

Returns the largest absolute value of the coefficients. Gives a sense of the scale of the quaternion. If all the coefficients are tiny or huge, we'll need to renormalize around 1, since we take reciprocals of the coefficients, and floating point precision is poor for floats.

void motive::QuadraticCurve::RangesMatchingSign ( const Range x_limits,
const float  sign,
RangeArray matching 
) const
inline

Get ranges above or below zero. Since a quadratic can cross zero at most twice, there can be at most two ranges. Ranges are clamped to x_limits. sign is used to determine above or below zero only–actual value is ignored.

float motive::QuadraticCurve::ReliableDiscriminant ( const float  epsilon) const

When Discriminant() is close to zero, set to zero. Often floating point precision problems can make the discriminant very slightly non-zero, even though mathematically it should be zero.

void motive::QuadraticCurve::Roots ( RootsArray roots) const
inline

Calculate the x-coordinates where this quadratic is zero, and put them into roots, in ascending order. Returns the 0, 1, or 2, the number of unique values put into roots.

void motive::QuadraticCurve::RootsInRange ( const Range x_limits,
RootsArray roots 
) const
inline

Calculate the x-coordinates within the range [start_x, end_x] where the quadratic is zero. Put them into roots. Return the number of unique values put into roots.

void motive::QuadraticCurve::RootsWithoutNormalizing ( RootsArray roots) const
inline

Same as Roots() but do not normalize the quadratic for precision. This function is not recommended, in general. Normalizing does not take much time, and floating point precision is something that we only like to think we can ignore. It may be safe to call this function if you are certain that your x^2 coefficient is near 1.

QuadraticCurve motive::QuadraticCurve::ScaleInX ( const float  x_scale) const
inline

Returns the curve f(x / x_scale), where f is the current quadratic. This stretches the curve along the x-axis by x_scale.

QuadraticCurve motive::QuadraticCurve::ScaleInXByReciprocal ( const float  x_scale_reciprocal) const
inline

Returns the curve f(x * x_scale_reciprocal), where f is the current quadratic. This stretches the curve along the x-axis by 1/x_scale_reciprocal

float motive::QuadraticCurve::SecondDerivative ( ) const
inline

Return the quadratic function's constant second derivative. f''(x) = 2*c2

float motive::QuadraticCurve::SecondDerivative ( const float  ) const
inline

Return the quadratic function's constant second derivative. Even though x is unused, we pass it in for consistency with other curve classes.

void motive::QuadraticCurve::ShiftLeft ( const float  x_shift)

Shift the curve along the x-axis: x_shift to the left. That is x_shift becomes the curve's x=0.

float motive::QuadraticCurve::ThirdDerivative ( const float  x) const
inline

Return the quadratic function's constant third derivative: 0. Even though x is unused, we pass it in for consistency with other curve classes. f'''(x) = 0


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