# Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

# Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
• 2 commits
• 2 files changed
• 1 contributor
Commits on Oct 27, 2011
 maettu `improvement of numerical integral calculation` `5607a83` maettu `layering rectangles behind function plot (setZValue())` `43384d2`
Showing with 45 additions and 18 deletions.
1. +9 −4 ala/CartesianCoordinateSystemElements/Point.py
2. +36 −14 integrale.pyw
13 ala/CartesianCoordinateSystemElements/Point.py
 @@ -112,10 +112,15 @@ def set_y(self, y): self.y = y self.setPosition() - def setPosition( self ): - self.setPos ( CST.toCcsCoord( - self.ccs, self.x, self.y ) - ) + def setPosition( self, x = False, y = False ): + if x == False and y == False: + self.setPos ( CST.toCcsCoord( + self.ccs, self.x, self.y ) + ) + else: + self.setPos( CST.toCcsCoord( + self.ccs, x, y ) + ) def setVisible( self, value ): self.visible = value
50 integrale.pyw
 @@ -38,6 +38,7 @@ from PyQt4.QtGui import ( QApplication, import sys import time +import math from ala.CartesianCoordinateSystem import CartesianCoordinateSystemWidget @@ -104,7 +105,8 @@ class MainWindow( QDialog ): self.end = 2 self.rectanglesFunction = [] - self.rectanglesIntegral = [] + #~ self.rectanglesIntegral = [] + self.pointsIntegral = [] self.numberRectanglesMax = 1000 @@ -117,11 +119,18 @@ class MainWindow( QDialog ): QPointF( 0, 0 ) , QPointF( 1, 0 ) ) ) self.rectanglesFunction[i].setVisible( False ) + # sets rectangle behind functionPlot + self.rectanglesFunction[i].setZValue( 2 ) - self.rectanglesIntegral.append( - self.ccsIntegral.addLine( QPointF(0,0), QPointF(1,0), False, False, 'blue' ) + #~ self.rectanglesIntegral.append( + #~ self.ccsIntegral.addLine( QPointF(0,0), QPointF(1,0), False, False, 'blue' ) + #~ ) + #~ self.rectanglesIntegral[i].setVisible( False ) + self.pointsIntegral.append( + self.ccsIntegral.addPoint( 0, 0, 5, 0, 0, 200 ) ) - self.rectanglesIntegral[i].setVisible( False ) + self.pointsIntegral[i].setVisible( False ) + self.pointsIntegral[i].setZValue( 2 ) self.numberRectanglesSpinBox = QSpinBox() self.numberRectanglesSpinBox.setMinimum ( 1 ) @@ -143,13 +152,12 @@ class MainWindow( QDialog ): self.functionPlot = self.ccsFunction.addFunction( self.function ) + self.functionPlot.setZValue( 1 ) self.changeFunction() self.integralPlot = self.ccsIntegral.addFunction( self.integral ) - - # TODO: check that on scale out ccs expand. - + self.integralPlot.setZValue( 1 ) self.scaleInButton = QPushButton( "scale in" ) self.scaleOutButton = QPushButton( "scale out" ) @@ -270,7 +278,7 @@ class MainWindow( QDialog ): # somewhat lazy input validation: set x=1 and testEval function try: # predefine x, because it is needed in eval - x = 1; + x = 1000; testEval = eval( str( self.editFunction.text() ) ) ok = True # if eval is o.k., then print "ok" @@ -284,7 +292,8 @@ class MainWindow( QDialog ): # integral are set invisible. for i in range ( self.numberRectanglesMax ): self.rectanglesFunction[i].setVisible( False ) - self.rectanglesIntegral[i].setVisible( False ) + #~ self.rectanglesIntegral[i].setVisible( False ) + self.pointsIntegral[i].setVisible( False ) # the function is redefined and painted. # TODO: this needs some input validation.. @@ -310,18 +319,31 @@ class MainWindow( QDialog ): x1 = self.start + float( self.end - self.start ) / self.numberRectangles * ( i ) x2 = self.start + float( self.end - self.start ) / self.numberRectangles * (i+1) - self.rectanglesFunction[i].setPosition( QPointF( x1, 0) , QPointF( x2, eval( self.function ) ) ) - self.rectanglesFunction[i].setVisible( True ) + #~ self.rectanglesFunction[i].setPosition( QPointF( x1, 0) , QPointF( x2, eval( self.function ) ) ) + #~ self.rectanglesFunction[i].setVisible( True ) # simply add sum up - ySum = ySum + eval( self.function ) + # improve accuracy (and cheat: change determination of x: must be where arithmetic middle + # of y1 and y2 is, not middle between x1 and x2, so to speak) + #~ ySum = ySum + eval( self.function ) + x = x1 + y1 = eval( self.function ) + x = x2 + y2 = eval( self.function ) + y = ( y1 + y2 ) / 2 + ySum = ySum + y + + self.rectanglesFunction[i].setPosition( QPointF( x1, 0) , QPointF( x2, y ) ) + self.rectanglesFunction[i].setVisible( True ) # The value of the integral is dependent on the whole range and the number # of rectangles. y = float( ySum ) * ( float (self.end - self.start) / self.numberRectangles ) - self.rectanglesIntegral[i].setPosition( QPointF(x1, y), QPointF(x2,y) ) - self.rectanglesIntegral[i].setVisible( True ) + #~ self.rectanglesIntegral[i].setPosition( QPointF(x1, y), QPointF(x2,y) ) + #~ self.rectanglesIntegral[i].setVisible( True ) + self.pointsIntegral[i].setPosition( x, y ) + self.pointsIntegral[i].setVisible( True ) self.reset()

### No commit comments for this range

Something went wrong with that request. Please try again.