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 q = -0.6461 - 0.4363 * I + 0.551 * J + 0.2976 * K >> mu = randv mu = 0.893 * I + 0.181 * J + 0.4121 * K >> [f, g] = factorq(q, mu, 'R') f = 0.6674 + 0.3212 * I - 0.4512 * J - 0.4979 * K g = -0.9681 - 0.2237 * I - 0.04535 * J - 0.1032 * K >> f .* g, q ans = -0.6461 - 0.4363 * I + 0.551 * J + 0.2976 * K q = -0.6461 - 0.4363 * I + 0.551 * J + 0.2976 * K >> scalar_product(f, mu) ans = 0