Generation

code to explanationFri, 23 Jun 2023

Eigen::Vector3d a(0, 0, 1); Eigen::Vector3d b(1, 0, 0); Eigen::Vector3d a_normalized = a.normalized(); Eigen::Matrix3d R; R.col(2) = a_normalized; Eigen::Vector3d b_prime; if (a_normalized[2] != 0.0) { b_prime << 0.0, a_normalized[2], -a_normalized[1]; } else { b_prime << -a_normalized[2], 0.0, a_normalized[0]; } Eigen::Vector3d c_prime = a_normalized.cross(b_prime); R.col(0) = c_prime; R.col(1) = b_prime; cout << "R:" << endl << R << endl; cout << "R.inverse:" << endl << R.inverse() << endl << endl; Eigen::Vector3d v = R * b;

Note that the third column of the rotation matrix is a normalized vector that is parallel to the vector a.

Questions about programming?Chat with your personal AI assistant