I\'m trying to make the switch from matrices to quaternions for skeletal animation in my OpenGL program, but I\'ve encountered a problem:
Given a number of unit quat
The easiest implementation (with Numpy in Python>=3.6) of Markley's solution would be:
import numpy as np
def q_average(Q, W=None):
if W is not None:
Q *= W[:, None]
eigvals, eigvecs = np.linalg.eig(Q.T@Q)
return eigvecs[:, eigvals.argmax()]
where Q is of size N-by-4. The resulting quaternion is already normalized.
In this case the weights are equal to 1 by default. Otherwise you can give a list of weights of size N (one per quaternion.)
That's it.