Can anyone help me out? I need to interpolate two rotation matrices linearly, and the only data I have are the two matricies and a delta. I've been trying to convert them to quaternions and then back, but everything I read on teh subject is kinda grey and hard to understand.

**0**

# Matrix Interpolation

Started by Phy, Apr 14 2005 03:08 PM

6 replies to this topic

Sponsor:

###
#2
Members - Reputation: **807**

Posted 14 April 2005 - 03:38 PM

If you aren't ready for quaternions (there's plenty of example source code on the internet), you can convert the matrices to axis-angle format, resulting in a vector and a scalar, which you can interpolate directly.

An even simpler method is to interpolate two rows or columns of the matrices as vectors, then create a new matrix from the resulting two interpolated vectors: cross (product) the two vectors to get the missing third vector, then orhonormalize (normalize/cross or dot-project (Gram-Schmidt)) the vectors to create an orthogonal matrix (3 orthonormal vectors make up a rotation matrix).

The first method may produce better results, and quaternions give more options for interpolation (lerp (linear), slerp (spherical linear), squad (cubic)).

Try www.google.com for more info on any keywords in this post.

An even simpler method is to interpolate two rows or columns of the matrices as vectors, then create a new matrix from the resulting two interpolated vectors: cross (product) the two vectors to get the missing third vector, then orhonormalize (normalize/cross or dot-project (Gram-Schmidt)) the vectors to create an orthogonal matrix (3 orthonormal vectors make up a rotation matrix).

The first method may produce better results, and quaternions give more options for interpolation (lerp (linear), slerp (spherical linear), squad (cubic)).

Try www.google.com for more info on any keywords in this post.

###
#4
Members - Reputation: **152**

Posted 15 April 2005 - 02:03 AM

If you have two 4x4 matricies X1 and X2, then you can linearly interpolate them by making 4x4=16 linear equations. Let x1 and x2 be the elements in the ith row and jth column of X1 and X2 respectively. Then with the parameter t, you have the equation:

f(t)=x1 + (x2 - x1)t

With such an equation for each pair of elements, you will have X1 when t=0 and X2 when t=1.

f(t)=x1 + (x2 - x1)t

With such an equation for each pair of elements, you will have X1 when t=0 and X2 when t=1.

###
#5
Members - Reputation: **2065**

Posted 15 April 2005 - 05:32 AM

Here's another option to consider. You can get the same interpolation as you would with quaternion slerp (albeit at greater expense) by finding the matrix that rotates from A to B, extracting the axis and angle from this matrix, scaling the angle, and then recomposing the matrix from the axis and angle and multiplying with A.

I'm at work now, but if you're interested in this method I can post details later (or perhaps someone else will in the meantime).

I'm at work now, but if you're interested in this method I can post details later (or perhaps someone else will in the meantime).

###
#6
Members - Reputation: **807**

Posted 15 April 2005 - 08:13 AM

Quote:

Original post by jyk

Here's another option to consider. You can get the same interpolation as you would with quaternion slerp (albeit at greater expense) by finding the matrix that rotates from A to B, extracting the axis and angle from this matrix, scaling the angle, and then recomposing the matrix from the axis and angle and multiplying with A.

I'm at work now, but if you're interested in this method I can post details later (or perhaps someone else will in the meantime).

Linear interpolation (Vectors, scalars):

delta = b - a;

// alpha = [0..1]

c = a + delta*alpha

3x3 rotation matrix form (right-hand element evaluated first):

delta = b * transpose(a) // transpose(a) followed by b.

delta.getAxisAngle(axis,deltaAngle)

// alpha = [0..1]

c = axisAngleToMatrix(axis,deltaAngle*alpha) * a

inline void interpolate(const Mat3 & a,const Mat3 & b,flt alpha,Mat3 & c) {

Mat3 delta = b ^ !a; // ^ = matrix product, ! = matrix transpose.

Vec3 axis;

flt deltaAngle;

delta.getAxisAngle(axis,deltaAngle);

Mat3 rm(axis,deltaAngle*alpha);

c = rm ^ a;

} // interpolate