<h1>Mapping the Left and Right Sides</h1>

<p>This step should be trivial. If I remember correctly, the CMU database animation skeletons have easily identifiable bone names. If not, then it's slightly less trivial. What you would have to do then would be to start at the root and go down each side. The bone structure should be the same for each animation though.</p>

<h1>Create the Rotation Matrix</h1>

<p>You should have three Euler angles: $X$, $Y$, and $Z$. You first need to create a <a href="https://en.wikipedia.org/wiki/Rotation_formalisms_in_three_dimensions#Euler_angles_.28_z-y.E2.80.99-x.E2.80.B3_intrinsic.29_.E2.86.92_Rotation_matrix" rel="nofollow">rotation matrix</a> for each bone. I use $\phi$ for $X$, $\theta$ for $Y$, and $\psi$ for $Z$ since this is a more common notation for matrix $R$. This is a right-handed matrix.</p>

<p>$$
\begin{bmatrix}
\cos(\theta)\cos(\psi) &amp;
\cos(\phi)\sin(\psi) + \sin(\phi)\sin(\theta)\cos(\psi) &amp;
\sin(\phi)\sin(\psi) - \cos(\phi)\sin(\theta)\cos(\psi) \\
- \cos(\theta)\sin(\psi) &amp;
\cos(\phi)\cos(\psi) - \sin(\phi)\sin(\theta)\sin(\psi) &amp;
\sin(\phi)\cos(\psi) + \cos(\phi)\sin(\theta)\sin(\psi) \\
\sin(\theta) &amp;
- \sin(\phi)\cos(\theta) &amp;
\cos(\phi)\cos(\theta)
\end{bmatrix}
$$</p>

<h1>Flip the Sides</h1>

<p>To flip the rotation matrix, you will need to multiply the axis you want to flip by $-1$. This is equivalent to <a href="https://en.wikipedia.org/wiki/Scaling_(geometry)#Matrix_representation" rel="nofollow">scaling in across that axis</a>. I will assume you want to scale across the x-axis for matrix $S$.</p>

<p>$$
\begin{bmatrix}
-1 &amp; 0 &amp; 0 \\
0 &amp; 1 &amp; 0 \\
0 &amp; 0 &amp; 1
\end{bmatrix}
$$</p>

<h1>Combine the Two Transforms</h1>

<p>Now just multiply these two matrices, and you get the opposite rotation:
$$T = R \times S$$</p>

<h1>Chain Together the Local Transforms</h1>

<p>Now you just need to apply forward kinematics, so you need to multiply each parent matrix by the local matrix to get an absolute transformation matrix.</p>

CC BY-SA 3.0
2016-10-03T02:42:41.747Z
Is the dot notation correct or even common for matrix multiplication? I've only seen it as a cross ($A \times B$) or omitted ($AB$).
Julien Guertault
CC BY-SA 3.0
2016-10-03T03:03:46.910Z
Oops, yeah I think you're right. I just get used to using dots for multiplication. :)
aces
CC BY-SA 3.0
2016-10-02T18:04:59.303Z
2016-10-03T03:16:27.113Z
2016-10-03T03:16:27.113Z
aces
<p>I have a skeleton (in <a href="http://research.cs.wisc.edu/graphics/Courses/cs-838-1999/Jeff/ASF-AMC.html" rel="nofollow">asf/amc format</a>), from <a href="http://mocap.cs.cmu.edu/" rel="nofollow">CMU's mocap database</a>. 
I'm using python, no libraries yet. (Blender in python mode doesn't work properly for this, as far as I know.)</p>

<p>I want to mirror the movement, swapping sides, assigning the right arm movement to the left arm and so on. </p>

<p>The number of degrees of freedom for each joint is between 1 and 3. Angles are stored in euler format, XYZ. All angles are local, relative to the parent bone.</p>

<p>Quite obviously, just renaming the objects (rhand&lt;->lhand) doesn't work. Where do I start?</p>

<geometry><motion>
Mirroring avatar
Fábio Dias
# Mirroring avatar

(Asked by: username_0 on 2016-09-30)

I have a skeleton (in [asf/amc format](http://research.cs.wisc.edu/graphics/Courses/cs-838-1999/Jeff/ASF-AMC.html)), from [CMU's mocap database](http://mocap.cs.cmu.edu/).
I'm using python, no libraries yet. (Blender in python mode doesn't work properly for this, as far as I know.)

I want to mirror the movement, swapping sides, assigning the right arm movement to the left arm and so on.

The number of degrees of freedom for each joint is between 1 and 3. Angles are stored in euler format, XYZ. All angles are local, relative to the parent bone.

Quite obviously, just renaming the objects (rhand<->lhand) doesn't work. Where do I start?

**Tags:** geometry, motion


---

## 1 answers

### Answer by username_1 on 2016-10-02. Score: 3

# Mapping the Left and Right Sides

This step should be trivial. If I remember correctly, the CMU database animation skeletons have easily identifiable bone names. If not, then it's slightly less trivial. What you would have to do then would be to start at the root and go down each side. The bone structure should be the same for each animation though.

# Create the Rotation Matrix

You should have three Euler angles: $X$, $Y$, and $Z$. You first need to create a [rotation matrix](https://en.wikipedia.org/wiki/Rotation_formalisms_in_three_dimensions#Euler_angles_.28_z-y.E2.80.99-x.E2.80.B3_intrinsic.29_.E2.86.92_Rotation_matrix) for each bone. I use $\phi$ for $X$, $\theta$ for $Y$, and $\psi$ for $Z$ since this is a more common notation for matrix $R$. This is a right-handed matrix.

$$
\begin{bmatrix}
\cos(\theta)\cos(\psi) &
\cos(\phi)\sin(\psi) + \sin(\phi)\sin(\theta)\cos(\psi) &
\sin(\phi)\sin(\psi) - \cos(\phi)\sin(\theta)\cos(\psi) \\
- \cos(\theta)\sin(\psi) &
\cos(\phi)\cos(\psi) - \sin(\phi)\sin(\theta)\sin(\psi) &
\sin(\phi)\cos(\psi) + \cos(\phi)\sin(\theta)\sin(\psi) \\
\sin(\theta) &
- \sin(\phi)\cos(\theta) &
\cos(\phi)\cos(\theta)
\end{bmatrix}
$$

# Flip the Sides

To flip the rotation matrix, you will need to multiply the axis you want to flip by $-1$. This is equivalent to [scaling in across that axis](https://en.wikipedia.org/wiki/Scaling_(geometry)#Matrix_representation). I will assume you want to scale across the x-axis for matrix $S$.

$$
\begin{bmatrix}
-1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{bmatrix}
$$

# Combine the Two Transforms

Now just multiply these two matrices, and you get the opposite rotation:
$$T = R \times S$$

# Chain Together the Local Transforms

Now you just need to apply forward kinematics, so you need to multiply each parent matrix by the local matrix to get an absolute transformation matrix.

> **Comments:**
> **username_2**: Is the dot notation correct or even common for matrix multiplication? I've only seen it as a cross ($A \times B$) or omitted ($AB$).  
> **username_1**: Oops, yeah I think you're right. I just get used to using dots for multiplication. :)  

---

