Support for averaging rotation quaternions
Hi,
not really an issue but more of a feature request; would it be possible to add robust averaging of rotation quaternions? This article describes such a way.
An implementation using 'raw' numpy arrays can be found here.
I might take a crack at doing this myself, but not sure when.
Kind regards, steven
I'm not opposed to this, but I'll also stipulate that I'm not a fan of the article by Markley et al. In particular, they unfairly characterize the "simple procedure" (which, btw, is implemented here). The normalization step is not "ad hoc"; it's just the correct optimum with respect to that metric. And the sign issue is not subtle — nor is it unexpected, nor hard to deal with by flipping signs to minimize distance. Moreover, it's not clear that any of these procedures is really more correct than any other in any way that matters; they're just optimizing different things. In my experience, they all arrive at nearly the same result in practice anyway, which seems to be what the article by Gramkow is saying.
I don't have time to really document or test these functions right now, but FWIW, I would probably start with something like this:
def mean_rotor_in_chordal_metric(q, weights=1):
wq = (weights * q).flattened.ndarray
return quaternionic.array(wq.sum(axis=0)).normalized
def mean_rotation_in_chordal_metric(q, weights=1):
wq = (weights * q).flattened.ndarray
m = np.einsum('ij,ik', wq, wq)
return quaternionic.array(np.copy(np.linalg.eigh(m)[1][:, -1]))
Note that the weights in this second function are probably more like the fourth root of Markley et al.'s weights. Also, einsum is a far more efficient way of evaluating that outer product sum, and just taking the last eigenvector works because eigh returns unit vectors in order of ascending eigenvalue.
While I'm thinking of it, another article I like for this sort of thing is (unfortunately pay-walled) here.
Thanks, that makes a lot of sense. I never looked into it deep enough, but it looks like I'll do just fine with the simple barycentric mean approach!