RotToQuat.m 288 B

12345678910
  1. % convert froma rotation vector in radians to a quaternion
  2. function quaternion = RotToQuat(rotVec)
  3. vecLength = sqrt(rotVec(1)^2 + rotVec(2)^2 + rotVec(3)^2);
  4. if vecLength < 1e-6
  5. quaternion = [1;0;0;0];
  6. else
  7. quaternion = [cos(0.5*vecLength); rotVec/vecLength*sin(0.5*vecLength)];
  8. end