<h2>Defining the problem</h2>
<p>The weighted arithmetic mean <span class="math-container">$\mu$</span>, of a set of vectors, minimizes squared L2 norm of the error (<span class="math-container">$v_i$</span>) to all elements of the set.</p>
<p><span class="math-container">$$
\begin{equation}
\begin{split}
v_i &amp;= \mu - x_i \\
\mu &amp;= \underset{\mu \in \mathbb{R^n}}{\text{argmin}} \; \frac{1}{2}\sum\limits_{v_i} w_i ||v_i||^2_2 \\
\end{split}
\end{equation}
$$</span></p>
<p>This empowers us to define special means, where we use different notions of distance.</p>
<h2>Specializing for rotations</h2>
<p>A reasonable notion of distance for SO(3) is the <em>angle</em> separating two rotations. That's <span class="math-container">$||\log(\mu \ q^{-1})||$</span> Your geometry library probably implements this <span class="math-container">$log$</span>, and expressions for it can be found <a href="http://ethaneade.com/lie.pdf" rel="nofollow noreferrer">here</a>. It is not the log one is accustomed to on the real numbers.</p>
<p>Intuition: Recall that every sequence of rotations corresponds to <a href="https://en.wikipedia.org/wiki/Euler%27s_rotation_theorem" rel="nofollow noreferrer">a single rotation about a single axis</a>, so the difference between a pair of rotations can always be summarized by a single angle.</p>
<p><span class="math-container">$$
\begin{equation}
\begin{split}
v_i &amp;= log(\mu \ x_i^{-1}) \\
\mu &amp;= \underset{\mu \in \mathbb{SO3}}{\text{argmin}} \sum\limits_{v_i} w_i || v_i||^2_2 \\
\end{split}
\end{equation}
$$</span></p>
<p>There's no analytical form for this minimum for more than two rotations. We can, however, treat this as a <a href="http://ethaneade.com/optimization.pdf" rel="nofollow noreferrer">least squares problem</a> and compute the result by Gauss-Newton.</p>
<p>To apply Gauss-Newton in general, for some error, we need to be able to find <span class="math-container">$\mathbf{J_i} = \frac{d}{d\mu}v_i(\mu)$</span>, which requires differentiating <span class="math-container">$v_i$</span>. Then we can take a step as</p>
<p><span class="math-container">$$
\begin{equation}
\begin{split}
\Delta \mu &amp;= \sum\limits_{i}(w_i \mathbf{J_i}^T \mathbf{J_i})^{-1} \sum\limits_{i} w_i \mathbf{J_i}^T v_i
\end{split}
\end{equation}
$$</span></p>
<p>Our error function cannot readily be differentiated, since its argument is a rotation <span class="math-container">$\mu$</span> and not a vector. We invent a parameter <span class="math-container">$\delta \in \mathbb{R^3}$</span> which we will <span class="math-container">$Exp$</span> into a rotation. This, we can differentiate</p>
<p><span class="math-container">$$
\begin{equation}
\begin{split}
v_i &amp;= log(Exp(\delta)\; \mu \ x_i^{-1}) \\ 
\mathbf{J_i} &amp;= \frac{d}{d\delta} v_i = \mathbf{I} \\
\end{split}
\end{equation}
$$</span></p>
<p>So the update to <span class="math-container">$\mu$</span> is</p>
<p><span class="math-container">$$
\begin{equation}
\begin{split}
\delta &amp;= \sum\limits_{i}(w_i \mathbf{J_i}^T \mathbf{J_i})^{-1} \sum\limits_{i} w_i \mathbf{J_i}^T v_i\\
\delta &amp;= \sum\limits_{i} w_i \sum\limits_{i} w_i v_i \\
\delta &amp;= \sum\limits_{i} w_i v_i
\end{split}
\end{equation}
$$</span></p>
<h1>Conclusion</h1>
<p><span class="math-container">$$
\begin{equation}
\begin{split}
\delta = \sum\limits_{i} w_i v_i &amp;= \sum\limits_{i}w_i log(\mu_{k}^{\mathstrut} x_{i}^{-1}) \\
\mu_{k + 1} &amp;= Exp(\delta) \mu_{k}\\
\end{split}
\end{equation}
$$</span>
This will converge quadratically to a mean.</p>
<p>Caveat emptor: for rotations, there may be many &quot;means&quot;. By analogy: What is the average point, on Earth's surface, of the north and south poles? Every point on the equator has equal right to be called the average. This is the case for all equispaced rotations.</p>

CC BY-SA 4.0
2020-05-05T18:01:59.740Z
2020-10-12T02:04:16.813Z
2020-10-12T02:04:16.813Z
Jacob Panikulam
<p>I have three quaternions A, B, C.</p>

<p>I also have a 3D vector P which describes the barycentric coordinate to interpolate.</p>

<p>I want to interpolate the three quaternions with respect to the barycentric coordinate P</p>

<p>This Image shows how to do it would A, B and C be usual vectors.</p>

<p><a href="https://i.sstatic.net/tz13g.png" rel="noreferrer"><img src="https://i.sstatic.net/tz13g.png" alt="enter image description here"></a></p>

<p>but how to calculate the quaternion interpolation?
Can I use the "slerp" command somehow?
How would the glm code look like?</p>

CC BY-SA 4.0
2020-05-04T18:49:39.397Z
See: https://gamedev.stackexchange.com/questions/62354/method-for-interpolation-between-3-quaternions/
There is no analytic solution, you'll have to use an iterative one.
lightxbulb
<glm>
Three quaternions interpolation with barycentric coordinates
Thomas
# Three quaternions interpolation with barycentric coordinates

(Asked by: username_0 on 2020-05-04)

I have three quaternions A, B, C.

I also have a 3D vector P which describes the barycentric coordinate to interpolate.

I want to interpolate the three quaternions with respect to the barycentric coordinate P

This Image shows how to do it would A, B and C be usual vectors.

[![enter image description here](https://i.sstatic.net/tz13g.png)](https://i.sstatic.net/tz13g.png)

but how to calculate the quaternion interpolation?
Can I use the "slerp" command somehow?
How would the glm code look like?

**Tags:** glm

> **Comments:**
> **username_1**: See: https://gamedev.stackexchange.com/questions/62354/method-for-interpolation-between-3-quaternions/ There is no analytic solution, you'll have to use an iterative one.  

---

## 1 answers

### Answer by username_2 on 2020-05-05. Score: 4 | Accepted answer

## Defining the problem

The weighted arithmetic mean $\mu$, of a set of vectors, minimizes squared L2 norm of the error ($v\_i$) to all elements of the set.

$$
\begin{equation}
\begin{split}
v\_i &= \mu - x\_i \\
\mu &= \underset{\mu \in \mathbb{R^n}}{\text{argmin}} \; \frac{1}{2}\sum\limits\_{v\_i} w\_i ||v\_i||^2\_2 \\
\end{split}
\end{equation}
$$

This empowers us to define special means, where we use different notions of distance.

## Specializing for rotations

A reasonable notion of distance for SO(3) is the *angle* separating two rotations. That's $||\log(\mu \ q^{-1})||$ Your geometry library probably implements this $log$, and expressions for it can be found [here](http://ethaneade.com/lie.pdf). It is not the log one is accustomed to on the real numbers.

Intuition: Recall that every sequence of rotations corresponds to [a single rotation about a single axis](https://en.wikipedia.org/wiki/Euler%27s_rotation_theorem), so the difference between a pair of rotations can always be summarized by a single angle.

$$
\begin{equation}
\begin{split}
v\_i &= log(\mu \ x\_i^{-1}) \\
\mu &= \underset{\mu \in \mathbb{SO3}}{\text{argmin}} \sum\limits\_{v\_i} w\_i || v\_i||^2\_2 \\
\end{split}
\end{equation}
$$

There's no analytical form for this minimum for more than two rotations. We can, however, treat this as a [least squares problem](http://ethaneade.com/optimization.pdf) and compute the result by Gauss-Newton.

To apply Gauss-Newton in general, for some error, we need to be able to find $\mathbf{J\_i} = \frac{d}{d\mu}v\_i(\mu)$, which requires differentiating $v\_i$. Then we can take a step as

$$
\begin{equation}
\begin{split}
\Delta \mu &= \sum\limits\_{i}(w\_i \mathbf{J\_i}^T \mathbf{J\_i})^{-1} \sum\limits\_{i} w\_i \mathbf{J\_i}^T v\_i
\end{split}
\end{equation}
$$

Our error function cannot readily be differentiated, since its argument is a rotation $\mu$ and not a vector. We invent a parameter $\delta \in \mathbb{R^3}$ which we will $Exp$ into a rotation. This, we can differentiate

$$
\begin{equation}
\begin{split}
v\_i &= log(Exp(\delta)\; \mu \ x\_i^{-1}) \\
\mathbf{J\_i} &= \frac{d}{d\delta} v\_i = \mathbf{I} \\
\end{split}
\end{equation}
$$

So the update to $\mu$ is

$$
\begin{equation}
\begin{split}
\delta &= \sum\limits\_{i}(w\_i \mathbf{J\_i}^T \mathbf{J\_i})^{-1} \sum\limits\_{i} w\_i \mathbf{J\_i}^T v\_i\\
\delta &= \sum\limits\_{i} w\_i \sum\limits\_{i} w\_i v\_i \\
\delta &= \sum\limits\_{i} w\_i v\_i
\end{split}
\end{equation}
$$

# Conclusion

$$
\begin{equation}
\begin{split}
\delta = \sum\limits\_{i} w\_i v\_i &= \sum\limits\_{i}w\_i log(\mu\_{k}^{\mathstrut} x\_{i}^{-1}) \\
\mu\_{k + 1} &= Exp(\delta) \mu\_{k}\\
\end{split}
\end{equation}
$$
This will converge quadratically to a mean.

Caveat emptor: for rotations, there may be many "means". By analogy: What is the average point, on Earth's surface, of the north and south poles? Every point on the equator has equal right to be called the average. This is the case for all equispaced rotations.


---

