Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double MainWindow::get_new_rotation_x(double angle, double xc, double x, double y, double yc)
- {
- return xc + (x - xc) * cos(angle * PI / 180) + (y - yc) * sin(angle * PI / 180);
- }
- double MainWindow::get_new_rotation_y(double angle, double xc, double x, double y, double yc)
- {
- return yc - (x - xc) * sin(angle * PI / 180) + (y - yc) * cos(angle * PI / 180);
- }
- void MainWindow::rotate_figure(double new_angle, double new_x, double new_y)
- {
- 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));
- 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));
- 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));
- 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));
- 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));
- figure.set_angle(figure.get_angle() + new_angle);
- }
- void MainWindow::on_rotateButton_clicked()
- {
- bool ok;
- double new_angle;
- double xdouble;
- double ydouble;
- QString angle_str = ui->lineEdit_3->text();
- QString x_str = ui->lineEdit_8->text();
- QString y_str = ui->lineEdit_9->text();
- new_angle = angle_str.toDouble(&ok);
- if (ok == false)
- {
- QMessageBox::critical(this, "ERROR", "Invalid input!");
- }
- else
- {
- xdouble = x_str.toDouble(&ok);
- if (ok == false)
- {
- QMessageBox::critical(this, "ERROR", "Invalid input!");
- }
- else
- {
- ydouble = y_str.toDouble(&ok);
- if (ok == false)
- {
- QMessageBox::critical(this, "ERROR", "Invalid input!");
- }
- }
- }
- if (ok == true)
- {
- rotate_figure(new_angle, xdouble, ydouble);
- if (check_points() == true)
- {
- if (current_state != state_number - 1)
- {
- rewrite_history();
- state_number = current_state + 1;
- }
- current_state++;
- state_number++;
- write_to_file();
- ui->lineEdit_3->clear();
- ui->lineEdit_8->clear();
- ui->lineEdit_9->clear();
- update(ui->frame->x(), ui->frame->y(), ui->frame->width(), ui->frame->height());
- }
- else
- {
- read_from_file(current_state);
- QMessageBox::critical(this, "ERROR", "The figure will be out of sight!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement