File Exchange

image thumbnail


version 1.1 (117 KB) by

This function computes the average (mean) quaternion.



Since quaternions are not regular vectors, but rather representations of orientation, an average quaternion cannot just be obtained by taking a weighted mean. This function implements the work done by F. Landis Merkley to calculate the average quaternion. The algorithm is explained by F. Landis Markley at:
For this particular implementation, I would also like to reference Mandar Harshe:
While being basic and straightforward, this algorithm is compared with rotqrmean from VoiceBox and found to produce quite similar results, yet it is more elegant, much simpler to implement and follow. (Though, there might be difference in signs)

Comments and Ratings (6)

Tolga Birdal

Tolga Birdal (view profile)

Dear Tobias,

Thank you for the remarks and comments.

The randomly generated qinit is always known to be positive. For the sake of comparisons using the sum of squared method, I wanted the signs to match. Assuming that the average quaternion result would not be very different from the mean of the random sampling, the signs should ideally match.

This is only done for the sake of comparison with qinit. Nothing else. If you could come up with a more fair metric, I would love to add that.

Finally, I agree that this not something I'm proud of : ) But nevertheless lets me to evaluate the quaternions, otherwise the element-wise difference might just be too large.

Hey, first i want to thank you for publicly offer this algorithm as Matlab methode. But i found something in your test file "test_avg_quat" that i dont understand. In line 25 you calculate the average Quaternion and in line 28 you just override it with the absolut value of this average. The absolut Quaternion or the representet Rotation is different to the before calculated average Rotation with the Markley Methode. Did you maybe want to invert the sign so that q=-q? That wouldnt chance the Rotation but the sign. Or what is the reason for taking the absolut value?

Thanks T.

Mosong Cheng


Tolga Birdal

Tolga Birdal (view profile)

Note that on 2001 Claus Gramkow showed that the naive mean is in fact a fair approximation of rotations:

I think re-orthagonalization using SVD after a standard averaging would suffice most applications.



Weighted average added.
Test function added.

MATLAB Release
MATLAB 7.9 (R2009b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today