Can anyone help make a rotating schedule? The application is written in C ++ Qt.

#include "mainwindow.h" #include "ui_mainwindow.h" #include <cfloat> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } // Ѐункция 1 double function_1(double x) { return x; } // Ѐункция 2 double function_2(double x) { return x * x; } // Π‘Ρ‚Ρ€ΡƒΠΊΡ‚ΡƒΡ€Π° привязки CheckBox-Π° ΠΊ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ class SelectFunction { public: SelectFunction(QCheckBox *cb, double (*funct)(double)) : checkBox(cb), function(funct) {} const QCheckBox* getCheck() { return checkBox; } double (* getFunction())(double) { return function; } private: QCheckBox *checkBox; // ΡƒΠΊΠ°Π·Π°Ρ‚Π΅Π»ΡŒ Π½Π° CheckBox double (*function)(double); // ΡƒΠΊΠ°Π·Π°Ρ‚Π΅Π»ΡŒ Π½Π° Ρ„ΡƒΠ½ΠΊΡ†ΠΈΡŽ }; void MainWindow::on_buttonDrawCharts_clicked() { layout=new QVBoxLayout(); std::vector<SelectFunction> checksFunct; checksFunct.push_back(SelectFunction(ui->checkFunc_1, function_1)); checksFunct.push_back(SelectFunction(ui->checkFunc_2, function_2)); bool ok_a, ok_b, ok_h; double a = ui->lineEdit_a->text().toDouble(&ok_a); double b = ui->lineEdit_b->text().toDouble(&ok_b); double h = ui->lineEdit_h->text().toDouble(&ok_h); if (!ok_a || !ok_b || !ok_h) { QMessageBox msgBox; msgBox.setText("НСкоррСктно Π·Π°Π΄Π°Π½Ρ‹ Π²Ρ…ΠΎΠ΄Π½Ρ‹Π΅ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹."); msgBox.exec(); return; } double minY = DBL_MAX, maxY = DBL_MIN; // ΠžΠΏΡ€Π΅Π΄Π΅Π»ΡΠ΅ΠΌ количСство Ρ‚ΠΎΡ‡Π΅ΠΊ int n = (b - a) / h + 2; if (n != 0) { // ΠžΡ‡ΠΈΡ‰Π°Π΅ΠΌ всС Π³Ρ€Π°Ρ„ΠΈΠΊΠΈ ui->widgetCharts->clearGraphs(); // ΠŸΠΎΠ΄ΠΏΠΈΡΡ‹Π²Π°Π΅ΠΌ оси Ox ΠΈ Oy ui->widgetCharts->xAxis->setLabel("X"); ui->widgetCharts->yAxis->setLabel("Y"); size_t number_charts = 0; // Π¦ΠΈΠΊΠ», ΠΏΠΎ всСм функциям for (size_t i = 0; i < checksFunct.size(); ++i) { if (checksFunct[i].getCheck()->isChecked()) { // Ссли установлСн CheckBox QVector<double> points_x(n), points_y(n); double x = a; // Π·Π°Π΄Π°Π΅ΠΌ Π½Π°Ρ‡Π°Π»ΡŒΠ½ΠΎΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ x double (*funct)(double) = checksFunct[i].getFunction(); // опрСдСляСм Ρ„ΡƒΠ½ΠΊΡ†ΠΈΡŽ // Π¦ΠΈΠΊΠ» ΠΏΠΎ всСму ΠΈΠ½Ρ‚Π΅Ρ€Π²Π°Π»Ρƒ, с Π·Π°Π΄Π°Π½Π½Ρ‹ΠΌ шагом for (int j = 0; j < n; ++j, x += h) { points_x[j] = x; points_y[j] = funct(x); // ΠžΠΏΡ€Π΅Π΄Π΅Π»ΡΠ΅ΠΌ максимальноС ΠΈ минимальноС Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΏΠΎ оси Oy if (points_y[j] < minY) minY = points_y[j]; if (points_y[j] > maxY) maxY = points_y[j]; } // ДобавляСм ΠΎΠ΄ΠΈΠ½ Π³Ρ€Π°Ρ„ΠΈΠΊ Π² widgetCharts ui->widgetCharts->addGraph(); // Π—Π°Π΄Π°Π΅ΠΌ Π³Ρ€Π°Ρ„ΠΈΠΊ для отрисовnumbersΠΊΠΈ ui->widgetCharts->graph(number_charts)->setData(points_x, points_y); // Π—Π°Π΄Π°Π΅ΠΌ Ρ‚ΠΈΠΏ Ρ‚ΠΎΡ‡Π΅ΠΊ ui->widgetCharts->graph(number_charts)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 3)); // Π£Π²Π΅Π»ΠΈΡ‡ΠΈΠ²Π°Π΅ΠΌ количСство Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌΡ‹Ρ… Π³Ρ€Π°Ρ„ΠΈΠΊΠΎΠ² ++number_charts; } } // Установим ΠΎΠ±Π»Π°ΡΡ‚ΡŒ, которая Π±ΡƒΠ΄Π΅Ρ‚ ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Ρ‚ΡŒΡΡ Π½Π° Π³Ρ€Π°Ρ„ΠΈΠΊΠ΅ ui->widgetCharts->xAxis->setRange(a, b); // для оси Ox ui->widgetCharts->yAxis->setRange(minY, maxY); // для оси Oy connect(sl,SIGNAL(valueChanged(int)),this,SLOT(mov())); // УстанавливаСм Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡ‚ΡŒ ΠΌΠ°ΡΡˆΡ‚Π°Π±ΠΈΡ€Π²Π°Π½ΠΈΡ Π³Ρ€Π°Ρ„ΠΈΠΊΠΎΠ² ui->widgetCharts->setInteraction(QCP::iRangeZoom, true); // УстанавливаСм Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡ‚ΡŒ пСрСтаскивания Π³Ρ€Π°Ρ„ΠΈΠΊΠΎΠ² ui->widgetCharts->setInteraction(QCP::iRangeDrag, true); // ΠŸΠ΅Ρ€Π΅Ρ€ΠΈΡΡƒΠ΅ΠΌ Π³Ρ€Π°Ρ„ΠΈΠΊ Π½Π° нашСм widgetCharts ui->widgetCharts->replot(); } } void MainWindow::mov() { QPainterPath temp1(QPointF(x_res*300,y_res*300)); for(double i=0; i>=-y_res*sqrt(6500); i-=x_res*3) { double x = cos(2*3.1415926535897932384626433832795*2*(sl->value()-49)/100); double y = sin(2*3.1415926535897932384626433832795*2*(sl->value()-49)/100); temp1.lineTo(x_res*(300+i*x+i*i*y*0.05),y_res*(300-(i*i*x*0.05-i*y))); } temp1.moveTo(x_res*300,y_res*300); for(double i=0; i<y_res*sqrt(6500); i+=x_res*3) { double x = cos(2*3.1415926535897932384626433832795*2*(sl->value()-49)/100); double y = sin(2*3.1415926535897932384626433832795*2*(sl->value()-49)/100); temp1.lineTo(x_res*(300+i*x+i*i*y*0.05),y_res*(300-(i*i*x*0.05-i*y))); } QPainterPath temp2(QPointF(x_res*300,y_res*300)); for(double i=0; i<y_res*300; i+=x_res*3) { double x = cos(2*3.1415926535897932384626433832795*2*(sl->value()-49)/100); double y = sin(2*3.1415926535897932384626433832795*2*(sl->value()-49)/100); temp2.lineTo(x_res*(300+i*x+i*y),y_res*(300-(i*xi*y))); } temp2.moveTo(x_res*300,y_res*300); for(double i=0; i>=-y_res*300; i-=x_res*3) { double x = cos(2*3.1415926535897932384626433832795*2*(sl->value()-49)/100); double y = sin(2*3.1415926535897932384626433832795*2*(sl->value()-49)/100); temp2.lineTo(x_res*(300+i*x+i*y),y_res*(300-(i*xi*y))); } scene->removeItem(path1); scene->removeItem(path2); path1 = new QGraphicsPathItem(temp1); path1->setPos(0,0); path1->setPen(QPen(Qt::blue)); path2 = new QGraphicsPathItem(temp2); path2->setPos(0,0); path2->setPen(QPen(Qt::red)); scene->addItem(path1); scene->addItem(path2); scene->setSceneRect(x_res*0,y_res*0,x_res*600,y_res*600); view->setScene(scene); } 
  • one
    What is a rotating schedule in your understanding? - Kromster
  • As a two-dimensional figure rotating around the origin - Salvador
  • Vseravno incomprehensible. Can you illustrate? - Kromster
  • What do you have in mind? It is necessary that the graph rotates a few degrees at a time (for example, by timer or function on itself) or, as an option, just a twist more click - Salvador

1 answer 1

If you need to rotate a point (or points) around an axis of coordinates by some angle angle (in degrees), then you can apply a rotation to them as follows:

  newX = Cos(angle / 180.0 * pi) * X + Sin(angle / 180.0 * pi) * Y; newY = Cos(angle / 180.0 * pi) * Y - Sin(angle / 180.0 * pi) * X; 

Note that newY uses to calculate X , so you need to use new variables for new values ​​— newX and newY .

  • you can still tell how to tie this change by scroling (when moving the slider) or by a timer - Salvador
  • @Salvador is unfamiliar with events in Qt, unfortunately. - Kromster