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