From b2767523f6f063f2fda534f1b509863cffaa86ea Mon Sep 17 00:00:00 2001 From: anisart Date: Sun, 13 May 2012 18:11:57 +0400 Subject: [PATCH] fixed out of range --- mainwindow.cpp | 12 ++++-------- mainwindow.h | 10 ++++++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index b6103b0..1a5ddc8 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -46,7 +46,7 @@ MainWindow::MainWindow(QWidget *parent) : solver(5, 5, 5, 1, 1, 1); paintGraphs(); - startTimer(10); + startTimer(1); } MainWindow::~MainWindow() @@ -56,7 +56,7 @@ MainWindow::~MainWindow() void MainWindow::paintGraphs() { - if (!solved) + if ((!solved)) return; curve1->setRawSamples(x1, y1, stepCount); @@ -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; @@ -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++; @@ -222,10 +220,8 @@ void MainWindow::timerEvent(QTimerEvent *) y1r.append(y1[l]); x2r.append(x2[l]); y2r.append(y2[l]); -// qDebug()<setSamples(x1r, y1r); curve4->attach(ui->qwtPlot_4); diff --git a/mainwindow.h b/mainwindow.h index 1d2f3ac..2cd7ea7 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -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; } @@ -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; }