Skip to content

Commit

Permalink
fixed out of range
Browse files Browse the repository at this point in the history
  • Loading branch information
anisart committed May 13, 2012
1 parent da7e9cf commit b276752
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
12 changes: 4 additions & 8 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ MainWindow::MainWindow(QWidget *parent) :

solver(5, 5, 5, 1, 1, 1);
paintGraphs();
startTimer(10);
startTimer(1);
}

MainWindow::~MainWindow()
Expand All @@ -56,7 +56,7 @@ MainWindow::~MainWindow()

void MainWindow::paintGraphs()
{
if (!solved)
if ((!solved))
return;

curve1->setRawSamples(x1, y1, stepCount);
Expand Down Expand Up @@ -116,8 +116,6 @@ void MainWindow::solver(double x10, double y10, double z10, double x20, double y
double X1, X2, X3, X4, Y1, Y2, Y3, Y4, Z1, Z2, Z3, Z4;
double X12, X22, X32, X42, Y12, Y22, Y32, Y42, Z12, Z22, Z32, Z42;

// if (pow(x1[i] - x2[i], 2) + pow(y1[i] - y2[i], 2) < r) qDebug()<<1; else qDebug()<<0;

X1 = dx1(x1[i - 1], y1[i - 1], z1[i - 1], x2[i - 1], y2[i - 1], z2[i - 1]) * dt;
Y1 = dy1(x1[i - 1], y1[i - 1], z1[i - 1], x2[i - 1], y2[i - 1], z2[i - 1]) * dt;
Z1 = dz1(x1[i - 1], y1[i - 1], z1[i - 1], x2[i - 1], y2[i - 1], z2[i - 1]) * dt;
Expand Down Expand Up @@ -210,7 +208,7 @@ void MainWindow::solver(double x10, double y10, double z10, double x20, double y

void MainWindow::timerEvent(QTimerEvent *)
{
if (!solved)
if ((!solved) or (j > stepCount - 2))
return;
j++;

Expand All @@ -222,10 +220,8 @@ void MainWindow::timerEvent(QTimerEvent *)
y1r.append(y1[l]);
x2r.append(x2[l]);
y2r.append(y2[l]);
// qDebug()<<l;
}
// qDebug()<<"===";
// if (pow(x1[j] - x2[j], 2) + pow(y1[j] - y2[j], 2) < r*r) qDebug()<<1; else qDebug()<<0;
qDebug()<<j;

curve4->setSamples(x1r, y1r);
curve4->attach(ui->qwtPlot_4);
Expand Down
10 changes: 6 additions & 4 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ class MainWindow : public QMainWindow
}


double dy1(double x1, double y1, double z1, double x2, double y2, double z2, bool sync = true) // false!!!
double dy1(double x1, double y1, double z1, double x2, double y2, double z2)
{
if (sync) return w1 * x1 + a * y1 + d * (y2 - y1);
if ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) < r * r)
return w1 * x1 + a * y1 + d * (y2 - y1);
else return w1 * x1 + a * y1;
}

Expand All @@ -68,9 +69,10 @@ class MainWindow : public QMainWindow
return -w2 * y2 - z2;
}

double dy2(double x1, double y1, double z1, double x2, double y2, double z2, bool sync = true) // false!!!
double dy2(double x1, double y1, double z1, double x2, double y2, double z2)
{
if (sync) return w2 * x2 + a * y2 + d * (y1 - y2);
if ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) < r * r)
return w2 * x2 + a * y2 + d * (y1 - y2);
else return w2 * x2 + a * y2;
}

Expand Down

0 comments on commit b276752

Please sign in to comment.