Path: blob/master/Tools/simulink/arducopter/functions/fromAxisAngle.m
9734 views
function q = fromAxisAngle(vec)1% Create a quaternion from its axis-angle representation. Just the rotation2% vector is given as input.3% Based on QuaternionT<T>::from_axis_angle(Vector3<T>)45q = zeros(4,1);6angle = single(sqrt(vec(1)^2 + vec(2)^2 + vec(3)^2));78if angle == 09q(1) = single(1);10q(2) = single(0);11q(3) = single(0);12q(4) = single(0);13else14axis = vec ./ angle;15% The following lines are based on QuaternionT<T>::from_axis_angle(const Vector3<T> &axis, T theta)16if angle == 017q(1) = single(1);18q(2) = single(0);19q(3) = single(0);20q(4) = single(0);21else22st2 = single(sin(0.5*angle));23q(1) = single(cos(0.5*angle));24q(2) = axis(1) * st2;25q(3) = axis(2) * st2;26q(4) = axis(3) * st2;27end28end2930