Files
lsim/src/graphicsellipseitem.cpp
catdog2 1f68e40c77 #1 fixed und einiges mehr
git-svn-id: http://svn.lsim.tuxzone.org/trunk@10 4bec179b-ab65-46ed-a5f8-55b8b5c735d0
2008-11-02 20:34:58 +00:00

177 lines
5.9 KiB
C++

/***************************************************************************
* Copyright (C) 2008 by Peter Dahlberg *
* pdahlberg@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "graphicsellipseitem.h"
#include <QDrag>
#include <QGraphicsSceneMouseEvent>
#include <QMimeData>
#include <QDebug>
#include "simulscene.h"
#include "probechargewidget.h"
#include <cmath>
#include "constants.h"
GraphicsEllipseItem::GraphicsEllipseItem() {
setFlag(ItemIsMovable);
setFlag(ItemIsSelectable);
setFlag(ItemIsFocusable);
//setCacheMode(QGraphicsItem::DeviceCoordinateCache);
//startTimer(100);
setMasse(9.10938188e-31);
setCharge(-1.6e-19);
myProbeChargeWidget = new ProbeChargeWidget(0,0,this);
currProbePath = new QList<QPointF>;
speedListX = new QList<double>;
speedListY = new QList<double>;
}
void GraphicsEllipseItem::timerEvent ( QTimerEvent * event ) {
static double vx;
vx++;
//moveBy(vx/20.0,vx/20.0*vx/20.0);
}
GraphicsEllipseItem::~GraphicsEllipseItem() {
}
void GraphicsEllipseItem::mousePressEvent ( QGraphicsSceneMouseEvent *event ) {
//QGraphicsEllipseItem::mousePressEvent(event);
}
/*!
\fn GraphicsEllipseItem::calculateProbePath()
*/
void GraphicsEllipseItem::calculateProbePath(QPointF startPoint, double startSpeedX , double startSpeedY) {
SimulScene* myScene = dynamic_cast<SimulScene*>(scene());
//wenn noch zu keiner scene gehoerend abbruch
if (myScene == 0) return;
//parameter der scene in lokale variablen uebernehmen
double timePerStep = myScene->getTimePerStep();
int steps = myScene->getSteps();
double meterPerPx = myScene->getMeterPerPx();
//listen leeren
currProbePath->clear();
speedListX->clear();
speedListY->clear();
//startwerte in die listen setzen
currProbePath->append(startPoint);
speedListX->append(startSpeedX);
speedListY->append(startSpeedY);
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, speedListX->at(i-1),speedListY->at(i-1), 'x');
double powerY = myScene->getPowerAt(currProbePath->at(i-1), charge, speedListX->at(i-1),speedListY->at(i-1), 'y');
double newspeedX = speedListX->at(i-1) + (powerX/myMasse * (timePerStep/1000.0));
double newspeedY = speedListY->at(i-1) + (powerY/myMasse * (timePerStep/1000.0));
//double deltaDistXconst = speedListX->at(i-1) * (timePerStep/1000.0); //v0*t
//double deltaDistYconst = speedListY->at(i-1) * (timePerStep/1000.0);
double deltaDistXconst = (speedListX->at(i-1) + newspeedX)/2.0 * (timePerStep/1000.0); //v0*t
double deltaDistYconst = (speedListY->at(i-1) + newspeedY)/2.0 * (timePerStep/1000.0); //mittel zw alt,neu um fehler zu mindern
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(newspeedX);
speedListY->append(newspeedY);
}
qDebug()<< "Probe Path: " <<*currProbePath;
qDebug()<< "speed x: "<<*speedListX;
qDebug()<< "speed y: "<<*speedListY;
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');
}
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 double& theValue ) {
if (masse == theValue) return;
masse = theValue;
emit masseChanged(theValue);
}
double GraphicsEllipseItem::getCharge() const {
return charge;
}
void GraphicsEllipseItem::setCharge ( const long double& theValue ) {
if (charge == theValue) return;
charge = theValue;
emit chargeChanged(theValue);
}
QWidget * GraphicsEllipseItem::getDockWidget() const
{
return myProbeChargeWidget;
}
QList<QPointF> * GraphicsEllipseItem::getCurrProbePath() {
return currProbePath;
}
double GraphicsEllipseItem::getStartSpeedX() const {
return startSpeedX;
}
void GraphicsEllipseItem::setStartSpeedX ( double theValue ) {
if (startSpeedX == theValue) return;
startSpeedX = theValue;
emit startSpeedXChanged(theValue);
}
double GraphicsEllipseItem::getStartSpeedY() const {
return startSpeedY;
}
void GraphicsEllipseItem::setStartSpeedY ( double theValue ) {
if (startSpeedY == theValue) return;
startSpeedY = theValue;
emit startSpeedYChanged(theValue);
}