I have vector x = (1,0,0). I need to find a set of rotations which transform it in such a way that it forms the magic angle with each axis. The magic angle is equal to $\arccos \left(\frac{1}{\sqrt{3}}\right)$.
It seems intuitive to rotate 45 degrees over z axis and then 90-magic over xy axis, but it doesn't work. Or perhaps there is something wrong with my code? I past it below.
Eigen::Vector3d x(1, 0, 0);
Eigen::Vector3d y(0, 1, 0);
Eigen::Vector3d z(0, 0, 1);
Eigen::Vector3d xy(1, 1, 0);
Eigen::Matrix3d rot = turboRotation(90-magic, xy);
rot = rot * turboRotation(45, z);
cout << acos((rot*x).dot(x))*180/M_PI << endl; //checking the angles
cout << acos((rot*x).dot(y))*180/M_PI << endl;
cout << acos((rot*x).dot(z))*180/M_PI << endl;
turboRotation function is:
Eigen::Matrix3d turboRotation(double deg, Eigen::Vector3d rotation_line)
{
rotation_line /= rotation_line.norm();
double a = deg*(M_PI / 180);
Eigen::Matrix3d rotationMatrix;
double x = rotation_line(0);
double y = rotation_line(1);
double z = rotation_line(2);
rotationMatrix << cos(a)+x*x*(1-cos(a)), x*y*(1 - cos(a))-z*sin(a), x*z*(1 - cos(a))+y*sin(a),
y*x*(1 - cos(a))+z*sin(a), cos(a)+y*y*(1 - cos(a)), y*z*(1 - cos(a)) + x*sin(a),
z*x*(1 - cos(a)) + y*sin(a), z*y*(1 - cos(a)) + x*sin(a), cos(a) + z*z*(1 - cos(a));
return rotationMatrix;
}