00001
00002 #include "HermiteFunction.h"
00003 #include "assertions.h"
00004 #include <math.h>
00005
00006
00007 namespace animal
00008 {
00009 namespace octree
00010 {
00011
00012 HermiteFunction::HermiteFunction( const FloatingPointType *coeffs, const unsigned int nCoeffs ) :
00013 _nCoeffs(nCoeffs)
00014 {
00015 Require( nCoeffs >= 2 );
00016 _coeffs = new FloatingPointType[_nCoeffs];
00017 _derivativeCoeffs = new FloatingPointType[_nCoeffs-1];
00018
00019 for( unsigned int i=0 ; i<_nCoeffs ; ++i )
00020 _coeffs[i] = coeffs[i];
00021 for( unsigned int i=0 ; i<_nCoeffs-1 ; ++i )
00022 {
00023 _derivativeCoeffs[i] = (i+1)*_coeffs[i+1];
00024 }
00025 }
00026 HermiteFunction::HermiteFunction( const HermiteFunction& hf )
00027 {
00028 _nCoeffs = hf._nCoeffs;
00029
00030 _coeffs = new FloatingPointType[_nCoeffs];
00031 _derivativeCoeffs = new FloatingPointType[_nCoeffs-1];
00032
00033 for( unsigned int i=0 ; i<_nCoeffs ; ++i )
00034 _coeffs[i] = hf._coeffs[i];
00035 for( unsigned int i=0 ; i<_nCoeffs-1 ; ++i )
00036 _derivativeCoeffs[i] = hf._derivativeCoeffs[i];
00037 }
00038 HermiteFunction HermiteFunction::operator=( const HermiteFunction& hf )
00039 {
00040 _nCoeffs = hf._nCoeffs;
00041
00042 _coeffs = new FloatingPointType[_nCoeffs];
00043 _derivativeCoeffs = new FloatingPointType[_nCoeffs-1];
00044
00045 for( unsigned int i=0 ; i<_nCoeffs ; ++i )
00046 _coeffs[i] = hf._coeffs[i];
00047 for( unsigned int i=0 ; i<_nCoeffs-1 ; ++i )
00048 _derivativeCoeffs[i] = hf._derivativeCoeffs[i];
00049
00050 return *this;
00051 }
00052
00053 HermiteFunction::~HermiteFunction()
00054 {
00055 delete []_coeffs;
00056 delete []_derivativeCoeffs;
00057 }
00058
00059
00060
00061 FloatingPointType HermiteFunction::compute( FloatingPointType x ) const
00062 {
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 FloatingPointType res = 0.0;
00073
00074 for( int i=_nCoeffs-1 ; i>=0 ; --i )
00075 {
00076
00077 res = res*x + _coeffs[i];
00078 }
00079 return res;
00080 }
00081
00082 FloatingPointType HermiteFunction::computeDerivative( FloatingPointType x ) const
00083 {
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 FloatingPointType res = 0.0;
00094
00095 for( int i=_nCoeffs-2 ; i>=0 ; --i )
00096 {
00097
00098 res = res*x + _derivativeCoeffs[i];
00099 }
00100 return res;
00101 }
00102
00103 }
00104 }
00105