Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members Related Pages Search
definiteintegralfunction.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "definiteintegralfunction.h"
00019
00020 #include <cmath>
00021
00022 #include <qpainter.h>
00023 #include <qpointarray.h>
00024 #include <qobject.h>
00025
00026 #include "fungparser.h"
00027 #include "fungmath.h"
00028
00029 DefiniteIntegralFunction::DefiniteIntegralFunction(BasicGraph *graph, int expressions, double _precision) : MathFunction(graph,expressions), precision(_precision)
00030 {
00031 pointsStorage = new QPointArray;
00032 }
00033
00034 DefiniteIntegralFunction::~DefiniteIntegralFunction()
00035 {
00036 delete pointsStorage;
00037 }
00038
00039 void DefiniteIntegralFunction::calculate_and_draw(QPainter *painter)
00040 {
00041 if ( lowerBounds.x() > upperBounds.x() )
00042 {
00043 QString s( QObject::tr("Invalid bounds") );
00044 setResult( s );
00045 return;
00046 }
00047
00048 pointsStorage->resize(upperBounds.x()-lowerBounds.x()+4);
00049
00050 double area = 0;
00051 (*pointsStorage)[upperBounds.x()-lowerBounds.x()+3] = QPoint(upperBounds.x(),toPixelYCoord(0));
00052 for (int i=lowerBounds.x(); i<=upperBounds.x(); i++)
00053 {
00054
00055 double height = precision;
00056 double alpha[] = {toGraphXCoord(i),animatorValue()};
00057 double alpha2[] = {toGraphXCoord(i+height),animatorValue()};
00058
00059 double baseone = expression->Eval(alpha);
00060 double basetwo = expression->Eval(alpha2);
00061 area += 0.5*(baseone+basetwo)*(toGraphXCoord(height)-toGraphXCoord(0));
00062
00063 (*pointsStorage)[i+1-lowerBounds.x()]=QPoint(i,toPixelYCoord(baseone));
00064 (*pointsStorage)[i+2-lowerBounds.x()]=QPoint((int)(ROUND(i+height)),toPixelYCoord(basetwo));
00065 }
00066 (*pointsStorage)[0] = QPoint(lowerBounds.x(),toPixelYCoord(0));
00067 draw_stored(painter);
00068
00069 QString s = QString("Definite Integral = %1").arg(area);
00070 setResult(s);
00071 }
00072
00073 void DefiniteIntegralFunction::draw_stored(QPainter *painter)
00074 {
00075 painter->save();
00076 painter->setBrush(QBrush(QColor(255,0,0),Qt::Dense4Pattern));
00077 painter->drawPolygon(*pointsStorage);
00078 painter->restore();
00079 }
00080
00081
|