/Utilities/Eul2Quat.m

https://github.com/softec17/GRETAA · MATLAB · 22 lines · 12 code · 4 blank · 6 comment · 0 complexity · c937ccf308f5636bc504a82073aafbf5 MD5 · raw file

  1. function [q0,q1,q2,q3] = Eul2Quat(bank,pitch,azimuth)
  2. % Takes Euler angles and calculates the equivalent quaternion
  3. % Inputs
  4. % bank,pitch,azimuth = Euler angles (rad) in 1,2,and 3 axis
  5. %
  6. % Outputs
  7. % q0,q1,q2,q3 = quaternions with q0 being the "scalar" value
  8. theta1 = azimuth;
  9. theta2 = pitch;
  10. theta3 = bank;
  11. t1 = theta1/2;
  12. t2 = theta2/2;
  13. t3 = theta3/2;
  14. q0 = cos(t1)*cos(t2)*cos(t3)+sin(t1)*sin(t2)*sin(t3);
  15. q1 = cos(t1)*cos(t2)*sin(t3)-sin(t1)*sin(t2)*cos(t3);
  16. q2 = cos(t1)*sin(t2)*cos(t3)+sin(t1)*cos(t2)*sin(t3);
  17. q3 = sin(t1)*cos(t2)*cos(t3)-cos(t1)*sin(t2)*sin(t3);
  18. return