// RotationMatrix.cc // Program to calculate coordinates after rotation #include #include using namespace std; void ComputeMatrix(float matrix[2][2], float angle); void RotateCoordinates(float rot[2][2], float old[2], float transformed[2]); int main() { float angle, point[2], transformedPoint[2]; float rotation[2][2]; // Get angle of rotation and initial position from input. cout << "Enter magnitude of rotation about z-axis in degrees: " ; cin >> angle; cout << "Input x and y coordinates: " << endl; cin >> point[0] >> point[1]; // Calculate coefficients of rotation matrix and transform point. // The value of pi is declared in math.h as M_PI. ComputeMatrix(rotation, (M_PI*angle/180.0)); RotateCoordinates(rotation, point, transformedPoint); // Output result. cout << "The coordinates in the rotated system (x,y) are "; cout << transformedPoint[0] << " and " << transformedPoint[1] << endl; return 0; } void ComputeMatrix(float matrix[2][2], float angle) { matrix[0][0] = cos(angle); matrix[0][1] = sin(angle); matrix[1][0] = -sin(angle); matrix[1][1] = cos(angle); } void RotateCoordinates(float rot[2][2], float old[2], float transformed[2]) { transformed[0] = (rot[0][0] * old[0]) + (rot[0][1] * old[1]); transformed[1] = (rot[1][0] * old[0]) + (rot[1][1] * old[1]); }