1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include <iostream>
#include<vector>
#include<cctype>
#include<cmath>
using namespace std;
void rotateX (float, vector<float>&, vector<float>&, vector<float>&, vector<float>&);
void rotateY (float, vector<float>&, vector<float>&, vector<float>&, vector<float>&);
void rotateZ (float, vector<float>&, vector<float>&, vector<float>&, vector<float>&);
int main(int argc, char **argv) {
vector<float> x_coords {0.0f};
vector<float> y_coords {3.0f};
vector<float> z_coords {0.0f};
vector<float> rot_x_coords {0.0f};
vector<float> rot_y_coords {0.0f};
vector<float> rot_z_coords {0.0f};
rotateZ(60, x_coords,y_coords, rot_x_coords, rot_y_coords);
rotateY(0, x_coords,z_coords, rot_x_coords,rot_z_coords);
rotateX(0, y_coords,z_coords, rot_y_coords, rot_z_coords);
for (size_t i{0}; i < rot_x_coords.size(); i++)
cout << rot_x_coords[i] << " ";
cout << endl;
for (size_t i{0}; i < rot_y_coords.size(); i++)
cout << rot_y_coords[i] << " ";
cout << endl;
for (size_t i{0}; i < rot_z_coords.size(); i++)
cout << rot_z_coords[i] << " ";
cout << endl;
}
void rotateZ (float angle, vector<float> &x_coords, vector<float>&y_coords,
vector<float> &rot_x_coords, vector<float>&rot_y_coords){
angle = angle * M_PI / 180.0;
float sinTheta = sin (angle);
float cosTheta = cos (angle);
for (size_t i{0}; i<x_coords.size(); i++){
rot_x_coords[i] = x_coords[i] * cosTheta - y_coords[i] * sinTheta;
rot_y_coords[i] = y_coords[i] * cosTheta + x_coords[i] * sinTheta;
}
}
void rotateY (float angle, vector<float> &x_coords, vector<float>&z_coords,
vector<float> &rot_x_coords, vector<float>&rot_z_coords){
angle = angle * M_PI / 180.0;
float sinTheta = sin (angle);
float cosTheta = cos (angle);
for (size_t i{0}; i<x_coords.size(); i++){
rot_x_coords[i] = x_coords[i] * cosTheta + z_coords[i] * sinTheta;
rot_z_coords[i] = z_coords[i] * cosTheta - x_coords[i] * sinTheta;
}
}
void rotateX (float angle, vector<float> &y_coords, vector<float>&z_coords,
vector<float> &rot_y_coords, vector<float>&rot_z_coords){
angle = angle * M_PI / 180.0;
float sinTheta = sin (angle);
float cosTheta = cos (angle);
for (size_t i{0}; i<z_coords.size(); i++){
rot_y_coords[i] = y_coords[i] * cosTheta - z_coords[i] * sinTheta;
rot_z_coords[i] = z_coords[i] * cosTheta + y_coords[i] * sinTheta;
}
}
}
|