I am trying to implement animation smoothing for a given set of keyframes. Some keyframes have "jitter" which i have to remove through my own algorithms. I am using the Unity game engine which has its own quaternion classes and such.(adsbygoogle = window.adsbygoogle || []).push({});

I looked into it, and using an Exponential Moving Average seems like a good idea. This approach works well for removing positional jitter, however when i use it with quaternions it causes some errors with rotations.

I am currently converting quaternions to euler angles, averaging, then converting back. However this doesn't seem to work. It causes my models to rotate in the wrong directions.

Here is the code i use:

Can anyone spot any obvious bugs?Code (Text):

void UpdateRotationEMA(int i, Quaternion q)

{

if (transforms[i] != null)

{

if (frameList[i] != null)

{

Vector3 pos = AvgPos(frameList[i], q.eulerAngles); //T1

transforms[i].rotation = Quaternion.Euler(pos);

frameList[i] = pos;

}

else

{

transforms[i].rotation = q;

frameList[i] = q.eulerAngles;

}

}

}

Vector3 AvgPos(Vector3 lastPos, Vector3 pos)

{

return (emaAlpha * pos + ((1f - emaAlpha) * lastPos));

}

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Averaging Quaternions

Loading...

Similar Threads - Averaging Quaternions | Date |
---|---|

I Bresar, Lemma 1.3 - Real Quaternions ... Division Algebras | Nov 20, 2016 |

The biquaternions and friends | Dec 12, 2015 |

Transforming a spatial average into a spectral average | Jan 24, 2014 |

Average minimum tries for prime factorization | May 24, 2009 |

E as an average | Mar 13, 2007 |

**Physics Forums - The Fusion of Science and Community**