% Rotation matrix from quaternion q = [q_0,qvector] see PCV (8.55) Usage: R = calc_Rot_q(q) q - double 4x1, quaternion R - double 3x3, 3D rotation matrix Wolfgang Förstner wfoerstn@uni-bonn.de See also calc_R_from_opq_kraus, calc_r_phi_from_R, calc_Rot_ab, calc_Rot_r, calc_Rot_rod, calc_Rot_rp, calc_Mq, calc_Mq_comm, calc_opq_from_R_Kraus
0001 %% Rotation matrix from quaternion 0002 % q = [q_0,qvector] 0003 % see PCV (8.55) 0004 % 0005 % Usage: 0006 % R = calc_Rot_q(q) 0007 % 0008 % q - double 4x1, quaternion 0009 % R - double 3x3, 3D rotation matrix 0010 % 0011 % Wolfgang Förstner 0012 % wfoerstn@uni-bonn.de 0013 % 0014 % See also calc_R_from_opq_kraus, calc_r_phi_from_R, calc_Rot_ab, 0015 % calc_Rot_r, calc_Rot_rod, calc_Rot_rp, calc_Mq, calc_Mq_comm, calc_opq_from_R_Kraus 0016 0017 function R = calc_Rot_q(q) 0018 0019 q0 = q(1); 0020 q1 = q(2); 0021 q2 = q(3); 0022 q3 = q(4); 0023 0024 R = [ 0025 q0^2+q1^2-q2^2-q3^2 2*(q1*q2-q3*q0) 2*(q1*q3+q2*q0); ... 0026 2*(q1*q2+q3*q0) q0^2-q1^2+q2^2-q3^2 2*(q2*q3-q1*q0); ... 0027 2*(q1*q3-q2*q0) 2*(q2*q3+q1*q0) q0^2-q1^2-q2^2+q3^2 ... 0028 ] ... 0029 /(q0^2+q1^2+q2^2+q3^2);