homoefeld berechnung und animation sollten grundlegend funktionieren

git-svn-id: http://svn.lsim.tuxzone.org/trunk@3 4bec179b-ab65-46ed-a5f8-55b8b5c735d0
This commit is contained in:
catdog2
2008-10-11 23:16:51 +00:00
parent 509cacdca6
commit c2a919a15e
8 changed files with 75 additions and 43 deletions

View File

@@ -18,4 +18,5 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <cmath>
const double PI = acos( -1.0 );
const double PI = acos( -1.0 );
const double SPEED_OF_LIGHT = 2.99792458e+8;

View File

@@ -24,6 +24,8 @@
#include <QDebug>
#include "simulscene.h"
#include "probechargewidget.h"
#include <cmath>
#include "constants.h"
GraphicsEllipseItem::GraphicsEllipseItem() {
setFlag(ItemIsMovable);
@@ -77,18 +79,22 @@ void GraphicsEllipseItem::calculateProbePath(QPointF startPoint, double startSpe
for(int i = 1; i< steps;++i) {
double myMasse = getMasse( sqrt( speedListX->at(i-1)*speedListX->at(i-1) + speedListY->at(i-1)*speedListY->at(i-1) ) );
qDebug()<< myMasse;
double powerX = myScene->getPowerAt(currProbePath->at(i-1), charge, 'x');
double powerY = myScene->getPowerAt(currProbePath->at(i-1), charge, 'y');
double deltaDistXconst = speedListX->at(i-1) * (timePerStep/1000.0);
double deltaDistXconst = speedListX->at(i-1) * (timePerStep/1000.0); //v0*t
double deltaDistYconst = speedListY->at(i-1) * (timePerStep/1000.0);
double deltaDistXaccel = 0.5 * (powerX/getMasse()) * (timePerStep/1000.0) * (timePerStep/1000.0);
double deltaDistYaccel = 0.5 * (powerY/getMasse()) * (timePerStep/1000.0) * (timePerStep/1000.0);
double deltaDistXaccel = 0.5 * (powerX/myMasse * (timePerStep/1000.0) * (timePerStep/1000.0)); // 1/2 * F/m * t*t
double deltaDistYaccel = 0.5 * (powerY/myMasse * (timePerStep/1000.0) * (timePerStep/1000.0));
double deltaDistX = (deltaDistXconst + deltaDistXaccel);
double deltaDistY = (deltaDistYconst + deltaDistYaccel);
currProbePath->append(QPointF(currProbePath->at(i-1).x() + deltaDistX/meterPerPx,currProbePath->at(i-1).y() + deltaDistY/meterPerPx));
speedListX->append(speedListX->at(i-1) + (powerX/getMasse()) * (timePerStep/1000.0));
speedListY->append(speedListY->at(i-1) + (powerY/getMasse()) * (timePerStep/1000.0));
currProbePath->append(QPointF(currProbePath->at(i-1).x() + deltaDistX/meterPerPx ,currProbePath->at(i-1).y() + deltaDistY/meterPerPx));
speedListX->append(speedListX->at(i-1) + (powerX/myMasse * (timePerStep/1000.0)) );
speedListY->append(speedListY->at(i-1) + (powerY/myMasse * (timePerStep/1000.0)) );
}
@@ -96,7 +102,6 @@ void GraphicsEllipseItem::calculateProbePath(QPointF startPoint, double startSpe
qDebug()<< "Probe Path: " <<*currProbePath;
qDebug()<< "speed x: "<<*speedListX;
qDebug()<< "speed y: "<<*speedListY;
qDebug()<<currProbePath->at(12);
qDebug()<<speedListY->at(12);
qDebug()<<"power x: "<< (double)myScene->getPowerAt(QPointF(0,0), charge, 'x');
qDebug()<<"power y: " << (double)myScene->getPowerAt(QPointF(0,0), charge, 'y');
@@ -104,12 +109,16 @@ void GraphicsEllipseItem::calculateProbePath(QPointF startPoint, double startSpe
}
long double GraphicsEllipseItem::getMasse() const {
return masse;
double GraphicsEllipseItem::getMasse(double speed) {
if(speed == 0) return masse;
else {
return masse / (sqrt(1- ( (speed/SPEED_OF_LIGHT)*(speed/SPEED_OF_LIGHT))));
}
}
void GraphicsEllipseItem::setMasse ( const long double& theValue ) {
void GraphicsEllipseItem::setMasse ( const double& theValue ) {
if (masse == theValue) return;
masse = theValue;
}
@@ -129,3 +138,7 @@ QWidget * GraphicsEllipseItem::getDockWidget() const
{
return myProbeChargeWidget;
}
QList<QPointF> * GraphicsEllipseItem::getCurrProbePath() {
return currProbePath;
}

View File

@@ -32,6 +32,8 @@ class GraphicsEllipseItem : public QObject , public QGraphicsEllipseItem {
QWidget* getDockWidget() const;
~GraphicsEllipseItem();
QList<QPointF> * getCurrProbePath();
@@ -58,12 +60,15 @@ class GraphicsEllipseItem : public QObject , public QGraphicsEllipseItem {
/*!
\param steps Anzahl der auszuf&uuml;renden Schriite
*/
void calculateProbePath (QPointF startPoint = QPointF(0,0), double startSpeedX = 0, double startSpeedY = 0);
void calculateProbePath (QPointF startPoint = QPointF(0,0) , double startSpeedX = 0, double startSpeedY = 0);
void setMasse ( const long double& theValue );
void setMasse ( const double& theValue );
long double getMasse() const;
//! Gibt die Masse zur&uuml;ck
/*!
\param speed alles != 0 relativistisch
*/
double getMasse(double speed);
void setCharge ( const long double& theValue );

View File

@@ -147,10 +147,25 @@ void lsim::createScene() {
void lsim::createDocks() {
QPushButton *button1 = new QPushButton("Loeschen");
QPushButton *button2 = new QPushButton("calculate");
ExpDoubleSpinBox *box = new ExpDoubleSpinBox;
box->setRange(-pow(10,33), pow(10,33));
box->setDecimals(4);
//box->setSuffix(" V");
ExpDoubleSpinBox *time_step_box = new ExpDoubleSpinBox;
time_step_box->setRange(-pow(10,33), pow(10,33));
time_step_box->setDecimals(20);
time_step_box->setKeyboardTracking(false);
time_step_box->setValue(simulscene->getTimePerStep());
connect(time_step_box, SIGNAL(valueChanged(double)),simulscene, SLOT(setTimePerStep(double)));
connect(simulscene, SIGNAL(timePerStepChanged(double)),time_step_box, SLOT(setValue( double )));
ExpDoubleSpinBox *meter_per_px_box = new ExpDoubleSpinBox;
meter_per_px_box->setRange(-pow(10,33), pow(10,33));
meter_per_px_box->setDecimals(20);
meter_per_px_box->setKeyboardTracking(false);
meter_per_px_box->setValue(simulscene->getMeterPerPx());
connect(meter_per_px_box, SIGNAL(valueChanged(double)),simulscene, SLOT(setMeterPerPx(double)));
connect(simulscene, SIGNAL(meterPerPxChanged(double)),meter_per_px_box, SLOT(setValue( double )));
QSlider *slider1 = new QSlider();
slider1->setMinimum(0);
@@ -163,7 +178,8 @@ void lsim::createDocks() {
layout->addWidget(button1);
layout->addWidget(button2);
layout->addWidget(slider1);
layout->addWidget(box);
layout->addWidget(time_step_box);
layout->addWidget(meter_per_px_box);
QWidget *widget2 = new QWidget;
widget2->setLayout(layout);

View File

@@ -74,32 +74,25 @@ SimulScene::SimulScene ( QObject* parent ) : QGraphicsScene ( parent ) {
addItem(ellipse1);
timer = new QTimeLine( (200e-3/8.0e+6) *1000 * 2e+8);
timer = new QTimeLine( 30000);
//qDebug()<< (200e-3/8.0e+6) *1000 * 2e+8;
timer->setFrameRange(0,100);
timer->setUpdateInterval(25);
timer->setCurveShape(QTimeLine::LinearCurve);
//timer->toggleDirection();
QGraphicsItemAnimation *ani = new QGraphicsItemAnimation();
ani = new QGraphicsItemAnimation();
ani->setItem(ellipse1);
ani->setTimeLine(timer);
qreal E = 40/(2e-2);
qreal q = -1.6022e-19;
qreal m = 9.1094e-31;
qreal vx = 8.0e+6;
qreal ax=0;
qreal ay=q*E/m;
for (int i=0; i<=200; ++i) {
qreal x=i;
ani->setPosAt(i/200.0, QPointF(x , 0.5 * ay * pow(( (x/1000) /vx),2) *1000 ));
//ani->setPosAt((t+360)/720.0, QPointF((t), 80*abs(t/180.0*3.14) ));
//qDebug()<<QPointF(x , 0.5 * ay * pow(( (x/1000) /vx),2) *1000 );
}
}
void SimulScene::startTimer() {
for (int i=0; i<getSteps(); ++i) {
//ani->setPosAt(i/200.0, QPointF(x , 0.5 * ay * pow(( (x/1000) /vx),2) *1000 ));
ani->setPosAt(i/(double)getSteps(), ellipse1->getCurrProbePath()->at(i) );
//qDebug()<< getSteps();
}
timer->start();
}
@@ -497,7 +490,7 @@ void SimulScene::setTimePerStep(double time) {
\fn SimulScene::startCalculation()
*/
void SimulScene::startCalculation() {
ellipse1->calculateProbePath();
ellipse1->calculateProbePath(ellipse1->pos());
}
@@ -519,8 +512,8 @@ void SimulScene::setSteps(int steps) {
}
long double SimulScene::getPowerAt(QPointF point, long double charge, char xy) {
long double dPower = 0;
double SimulScene::getPowerAt(QPointF point, double charge, char xy) {
double dPower = 0;
for(int i = 0; i < items(point).size(); ++i) {
//HomoEFieldItems Abarbeiten
if (qgraphicsitem_cast<HomoEFieldItem*> (items(point).at(i)) != 0) {
@@ -550,6 +543,7 @@ double SimulScene::getMeterPerPx() const {
void SimulScene::setMeterPerPx ( double theValue ) {
if (theValue == meterPerPx) return;
meterPerPx = theValue;
emit meterPerPxChanged(theValue);
}

View File

@@ -27,6 +27,7 @@ class HomoEFieldItem;
class QGraphicsRectItem;
class QGraphicsItemGroup;
class GraphicsEllipseItem;
class QGraphicsItemAnimation;
/**
@author Peter Dahlberg <pdahlberg@gmail.com>
@@ -49,7 +50,7 @@ class SimulScene : public QGraphicsScene {
\param charge Die Ladung, auf die die Kraft ausge&uuml;bt wird
\param xy x oder y-Richtung
*/
long double getPowerAt(QPointF point, long double charge, char xy);
double getPowerAt(QPointF point, double charge, char xy);
QWidget* getProbeDockWidget() const;
public slots:
@@ -74,6 +75,7 @@ class SimulScene : public QGraphicsScene {
void sceneModeChanged(int mode);
void stepsChanged(int steps);
void timePerStepChanged(double timePerStep);
void meterPerPxChanged(double meterPerPx);
private:
QTimeLine *timer;
@@ -90,6 +92,7 @@ class SimulScene : public QGraphicsScene {
QGraphicsItem *pressedResizeItem;
GraphicsEllipseItem *ellipse1;
QGraphicsItemAnimation *ani;
//rechtecke zur groesenaenderung