3 ms·
Oh you can absolutely average rotation quaternions, even weighted. You just use regular online computation of mean, express it in terms of linear mix operations
by xaedes 4y ago
Oh you can absolutely average rotation quaternions, even weighted.
You just use regular online computation of mean, express it in terms of linear mix operations (x k + (1-k) y) and then use quaternion slerp for the linear mix:
mean = zero_rotation_quaternion
wsum = 0
for w,qt in zip(weights, quaternions):
wsum += w
# regular online mean computation:
# delta = qt - mean
# mean := mean + delta*w/wsum
# express as linear mix:
# mean := mean + qt*w/wsum - mean*w/wsum
# mean := mean * (1-w/wsum) + qt*w/wsum
# i.e. mean is linear mix between mean and qt, with k=w/sum
mean = slerp(mean, qt, w/wsum)
return mean
- chombier 4y agoExcept the quaternion product is non-commutative, so the result of your algorithm will depend on the ordering of your `quaternions` array (which may be acceptable in practice), whereas Karcher mean does not.
- scythe 4y agoThe quaternion product is non-commutative, but quaternion addition is commutative. As far as I can tell he just takes weighted averages, which is a commutative operation. Rotations in 3D are inherently non-commutative, so whenever you work with multiple axes, the order matters. Interpolating between two rotations is a special case because you're not actually rotating the rotation operators themselves.
- chombier 4y ago> As far as I can tell he just takes weighted averages, which is a commutative operation. It works when doing LERPs (linear interpolations) but the algorithm above uses SLERPs (spherical interpolations) which can be expressed with quaternion products/exponentials/logarithms, so I think the order does matter. A quick numerical check with 3 quaternions and uniform weights seems to confirm this.
- xaedes 4y agoSlerp is no binary operator, but suppose we only look at the two quaternions, then it is "commutative". You can swap both quaternions, but you must use (1-t) for the interpolation factor instead of just t. Wikipedia[1] lists some equivalent formulas for quaternion slerp: slerp(q0, q1, t) = (q0 * q1^(-1))^(1-t) * q1 slerp(q0, q1, t) = (q1 * q0^(-1))^t * q0 There you can see that quaternion products are used, yes, but the operation is also commutative, when using (1-t) instead of t. When the order in online average computation is different, the t naturally adapts to the correct value, depending on the weights. These arguments about commutativity and order are really just the same as for regular linear interpolation (LERP) and online average computation. [1] https://en.wikipedia.org/wiki/Slerp#Quaternion_Slerp https://en.wikipedia.org/wiki/Slerp#Quaternion_Slerp
- chombier 4y agoYes, SLERP is commutative along one-parameter subgroups by definition. The problem arises as soon as more than two quaternions are to be averaged using the above procedure. Again, using 3 quaternions and uniform weights with the above algorithm gives slerp(slerp(a, b, 1/2), c, 1/3) but medians in a spherical triangle don't cross at 2:1 ratio in general.
- xaedes 4y agoHm yes. I also played with a few a examples. I have to admit, the order seems to only be really irrelevant when averaging rotations around one axis to avoid triangles. Thanks for pointing out. For averaging rotations that are similar the differences are tiny, but still. What a bummer.
- gbjw 4y agoFor anyone looking into this, Rotation Averaging by Hartley et al. (2011) is a must-read on the subject of rotation averaging: https://users.cecs.anu.edu.au/~hartley/Papers/PDF/Hartley-Trumpf:Rotation-averaging:IJCV.pdf https://users.cecs.anu.edu.au/~hartley/Papers/PDF/Hartley-Tr...