Weighted interpolation of multiple quaternions

Hi. Three has a `slerp` for quaterions, but doesn’t implement weighted interpolation of multiple (e.g. 4) quaternions. Not complaining, that does seem too niche of a problem for Three to tackle.

Just wondering if anyone has any experience, code, recommendations for doing this in Three.

I understand it’s possible to build a quadratic quaternion interpolation (aka “squad”) out of a few slerp calls. But I would like to calculate a quaternion based on four input quaternions and four weights.

Something like:

``````const inputQuats = [ q1, q2, q3, q4 ];
const inputWeights = [ 0.2, 0.5, 0.1, 0.2 ]; // adds to 1.0
const outputQuat = weightedQuaternion(inputQuats, inputWeights);
``````

Anyone know of an implementation of the hypothetical `weightedQuaternion` here, or how I’d go about it?

SkinnedMesh is doing this internally yea?

1 Like

I’m not sure, but I think skinning interpolates “vanilla” vectors, in cartesian space. My understanding is that quaternions can’t be interpolated the same way because they’re not … “linear”? (e.g. The angles of a triangle on the surface of a sphere is greater than 180º)

(FYI I am waving my hands wildly as I type this.)

If the quaternions are not wildly different, often linear interpolation is fine. If you need correct interpolation you can use .slerp instead of .lerp.