Documentation


HermiteFunction.cpp

Go to the documentation of this file.
00001 
00002 #include "HermiteFunction.h"
00003 #include "assertions.h"
00004 #include <math.h>
00005 //#include <iostream.h>
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     if( x < 0.0 )
00065         x = -x;
00066         
00067     Require( x<=2.0 );
00068     if( x > 1.0 )
00069         x = 2.0 - x;
00070 */
00071         
00072     FloatingPointType res = 0.0;
00073     //std::cerr << "x is " << x << "\n";
00074     for( int i=_nCoeffs-1 ; i>=0 ; --i )
00075     {
00076         //std::cerr << "we're adding " << res*x + _coeffs[i] << "( coeffs is " << _coeffs[i] << "\n";
00077         res = res*x + _coeffs[i];
00078     }
00079     return res;
00080 }
00081 
00082 FloatingPointType HermiteFunction::computeDerivative( FloatingPointType x ) const
00083 {
00084 /*  
00085     if( x < 0.0 )
00086         x = -x;
00087         
00088     Require( x<=2.0 );
00089     if( x > 1.0 )
00090         x = 2.0 - x;
00091 */
00092     
00093     FloatingPointType res = 0.0;
00094     //std::cerr << "Derivative : x is " << x << "\n";
00095     for( int i=_nCoeffs-2 ; i>=0 ; --i )
00096     {
00097         //std::cerr << "For i = " << i << "( coeffs is " << _derivativeCoeffs[i] << "\n";
00098         res = res*x + _derivativeCoeffs[i];
00099     }
00100     return res;
00101 }
00102 
00103 }
00104 }
00105 

Generated on Thu Dec 23 13:52:25 2004 by doxygen 1.3.6