QQFLY.NET
← Writing

How do you average rotations?

A question on Zhihu caught my attention: given several dozen measurements of an object's orientation, how do you find their average?

The measurements were available as rotation matrices and quaternions. It sounds like a routine calculation, until you ask what “average” means for a rotation.

The original question

Defining the average

The definition used here is geometric: given n elements The set of n given elements, find a representative point A point x in the space in the same space by minimizing a distance-based objective.

For rotations, that gives the following optimization problem:

Optimization objective for the average rotation

The distance between two elements of SO(3) is defined by:

Distance between two rotations in SO(3)

We can solve this numerically for a set of n rotations. But is there an analytical solution?

Three approaches are easy to imagine:

  1. Convert to Euler angles and average the three components separately.
  2. Use quaternions and average their four components, following the method in the Unity discussion on quaternion averaging.
  3. Map the rotations to a tangent space with Log, average them in that vector space, then map the result back to SO(3) with Exp.

I implemented all three and compared them with numerical optimization on three randomly generated datasets.

Three comparisons

1. Rotations spread across SO(3). The first set is sampled uniformly over the rotation space.

Dataset 1: rotations sampled uniformly over SO(3)

Here are the results from the three averaging methods and numerical optimization:

Dataset 1: average rotations from four methods
(a) Euler angles; (b) quaternions; (c) tangent space; (d) numerical optimization.

The video puts the four results together.

2. Rotations close to the identity. The second set is sampled within a small neighborhood of SO3.Identity().

Dataset 2: rotations sampled near the identity
Dataset 2: average rotations from four methods
(a) Euler angles; (b) quaternions; (c) tangent space; (d) numerical optimization.

3. The same cluster, rotated elsewhere. For the third set, I left-multiplied every rotation in the second set by a randomly chosen rotation matrix.

Dataset 3: the second set left-multiplied by a random rotation
Dataset 3: average rotations from four methods
(a) Euler angles; (b) quaternions; (c) tangent space; (d) numerical optimization.

What the experiments suggest

In these examples, none of the three shortcuts matches the numerical solution exactly. As of 2021, there seemed to be no analytical solution to the problem.

There is a useful approximation, though: when the input rotations are close to one another, the quaternion-averaging method can give a reasonably accurate result.

← Writing