Quadratic.cxx

Go to the documentation of this file.
00001 
00012 #ifdef _MSC_VER
00013 #include "msdevstudio/MSconfig.h"
00014 #endif
00015 
00016 #include "Quadratic.h"
00017 
00018 #include "FunctionHelper.h"
00019 
00020 #include <cassert>
00021 
00022 #ifdef ITERATOR_MEMBER_DEFECT
00023 using namespace std;
00024 #else
00025 using std::vector;
00026 #endif
00027 
00028 namespace hippodraw {
00029 
00030 Quadratic::Quadratic ( )
00031 {
00032   initialize ();
00033 }
00034 
00035 Quadratic::Quadratic ( double intercept, double linear, double quad )
00036 {
00037   initialize ();
00038 
00039   m_parms[0] = intercept;
00040   m_parms[1] = linear;
00041   m_parms[2] = quad;
00042 }
00043 
00044 void Quadratic::initialize ()
00045 {
00046   m_name = "Quadratic";
00047 
00048   m_parm_names.push_back ( "Intercept" );
00049   m_parm_names.push_back ( "Linear" );
00050   m_parm_names.push_back ( "Quad" );
00051 
00052   resize ();
00053 }
00054 
00055 FunctionBase * Quadratic::clone () const
00056 {
00057   return new Quadratic ( *this );
00058 }
00059 
00060 double Quadratic::operator () ( double x ) const
00061 {
00062   return m_parms[0] + x * ( m_parms[1] + x * m_parms[2] );
00063 }
00064 
00065 /* virtual */
00066 void 
00067 Quadratic::
00068 initialParameters ( const FunctionHelper * helper )
00069 {
00070   double min_x = helper->minCoord ();
00071   double max_x = helper->maxCoord ();
00072 
00073   double min_y = helper->minValue ();
00074   double max_y = helper->maxValue ();
00075 
00076   m_parms[1] = ( max_y - min_y ) / ( max_x - min_x );
00077   m_parms[0] = max_y - m_parms[1] * max_x;
00078   m_parms[2] = m_parms[1] / ( 5.0 * ( max_x - min_x ) );
00079 }
00080 
00081 double Quadratic::derivByParm ( int i, double x ) const
00082 {
00083   switch ( i ) {
00084   case 0 :
00085     return 1.0;
00086     break;
00087 
00088   case 1 :
00089     return x; 
00090     break;
00091 
00092   case 2 :
00093     return x * x;
00094     break;
00095 
00096   default :
00097     assert (false );
00098     break;
00099   }
00100   return 0.0;
00101 }
00102 
00103 } // namespace hippodraw
00104 

Generated for HippoDraw Class Library by doxygen