Factorisation of a quaternion
[f, g, theta] = factorq(q, mu, L)
factorq factorizes a quaternion q, using the pure quaternion mu, such that the vector parts of the factors are orthogonal.
On return f is a quaternion, g is a unit quaternion, and theta is an angle, such that g = exp(mu .* theta) and g .* f = q or f .* g = q according as to whether the third parameter is specified as 'L' or 'R', respectively (the exponential factor is on the left or right).
f will be orthogonal to mu and therefore also to the vector part of exp(mu .* theta) = mu .* sin(theta).
>> q = randq; >> mu = randv; >> [f, theta] = factorq(q, mu, 'R') f = 0.3864 + 0.2327 * I - 0.8896 * J + 0.07195 * K theta = -2.1688 >> f .* exp(mu .* theta), q ans = -0.2175 - 0.1983 * I + 0.5497 * J + 0.7818 * K q = -0.2175 - 0.1983 * I + 0.5497 * J + 0.7818 * K >> scalar_product(f, mu) ans = 1.8041e-16