Advertisement
555oya

roration

May 22nd, 2022
933
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. double MainWindow::get_new_rotation_x(double angle, double xc, double x, double y, double yc)
  2. {
  3.     return xc + (x - xc) * cos(angle * PI / 180) + (y - yc) * sin(angle * PI / 180);
  4. }
  5.  
  6. double MainWindow::get_new_rotation_y(double angle, double xc, double x, double y, double yc)
  7. {
  8.     return yc - (x - xc) * sin(angle * PI / 180) + (y - yc) * cos(angle * PI / 180);
  9. }
  10.  
  11. void MainWindow::rotate_figure(double new_angle, double new_x, double new_y)
  12. {
  13.     figure.set_a(get_new_rotation_x(new_angle, new_x, figure.get_ax(), figure.get_ay(), new_y), get_new_rotation_y(new_angle, new_x, figure.get_ax(), figure.get_ay(), new_y));
  14.     figure.set_b(get_new_rotation_x(new_angle, new_x, figure.get_bx(), figure.get_by(), new_y), get_new_rotation_y(new_angle, new_x, figure.get_bx(), figure.get_by(), new_y));
  15.     figure.set_c(get_new_rotation_x(new_angle, new_x, figure.get_cx(), figure.get_cy(), new_y), get_new_rotation_y(new_angle, new_x, figure.get_cx(), figure.get_cy(), new_y));
  16.     figure.set_d(get_new_rotation_x(new_angle, new_x, figure.get_dx(), figure.get_dy(), new_y), get_new_rotation_y(new_angle, new_x, figure.get_dx(), figure.get_dy(), new_y));
  17.     figure.set_center(get_new_rotation_x(new_angle, new_x, figure.get_center_x(), figure.get_center_y(), new_y), get_new_rotation_y(new_angle, new_x, figure.get_center_x(), figure.get_center_y(), new_y));
  18.     figure.set_angle(figure.get_angle() + new_angle);
  19. }
  20.  
  21. void MainWindow::on_rotateButton_clicked()
  22. {
  23.     bool ok;
  24.     double new_angle;
  25.     double xdouble;
  26.     double ydouble;
  27.  
  28.     QString angle_str = ui->lineEdit_3->text();
  29.     QString x_str = ui->lineEdit_8->text();
  30.     QString y_str = ui->lineEdit_9->text();
  31.  
  32.     new_angle = angle_str.toDouble(&ok);
  33.     if (ok == false)
  34.     {
  35.         QMessageBox::critical(this, "ERROR", "Invalid input!");
  36.     }
  37.     else
  38.     {
  39.         xdouble = x_str.toDouble(&ok);
  40.         if (ok == false)
  41.         {
  42.             QMessageBox::critical(this, "ERROR", "Invalid input!");
  43.         }
  44.         else
  45.         {
  46.             ydouble = y_str.toDouble(&ok);
  47.             if (ok == false)
  48.             {
  49.                 QMessageBox::critical(this, "ERROR", "Invalid input!");
  50.             }
  51.         }
  52.     }
  53.  
  54.     if (ok == true)
  55.     {
  56.         rotate_figure(new_angle, xdouble, ydouble);
  57.         if (check_points() == true)
  58.         {
  59.             if (current_state != state_number - 1)
  60.             {
  61.                 rewrite_history();
  62.                 state_number = current_state + 1;
  63.             }
  64.             current_state++;
  65.             state_number++;
  66.             write_to_file();
  67.             ui->lineEdit_3->clear();
  68.             ui->lineEdit_8->clear();
  69.             ui->lineEdit_9->clear();
  70.             update(ui->frame->x(), ui->frame->y(), ui->frame->width(), ui->frame->height());
  71.         }
  72.         else
  73.         {
  74.             read_from_file(current_state);
  75.             QMessageBox::critical(this, "ERROR", "The figure will be out of sight!");
  76.         }
  77.     }
  78. }
  79.  
Advertisement
RAW Paste Data Copied
Advertisement