YZXrotation.m 774 B

1234567891011121314151617181920212223
  1. % YZXrotation.m
  2. %
  3. % This function calculates the rotation matrix to the coordinate system of
  4. % reference.
  5. function rot = YZXrotation(vec, tiltRads)
  6. theta = asin(vec(2));
  7. psi = 0;
  8. if (abs(theta) < pi/2 - 0.01)
  9. psi = atan2(vec(3), vec(1));
  10. end
  11. rot = zeros(3);
  12. rot(1,1) = cos(theta)*cos(psi);
  13. rot(1,2) = -sin(theta);
  14. rot(1,3) = cos(theta)*sin(psi);
  15. rot(2,1) = cos(tiltRads)*sin(theta)*cos(psi) + sin(tiltRads)*sin(psi);
  16. rot(2,2) = cos(tiltRads)*cos(theta);
  17. rot(2,3) = cos(tiltRads)*sin(theta)*sin(psi) - sin(tiltRads)*cos(psi);
  18. rot(3,1) = sin(tiltRads)*sin(theta)*cos(psi) - cos(tiltRads)*sin(psi);
  19. rot(3,2) = sin(tiltRads)*cos(theta);
  20. rot(3,3) = sin(tiltRads)*sin(theta)*sin(psi) + cos(tiltRads)*cos(psi);
  21. end