• FEATURED
• FEATURED
• FEATURED
• FEATURED
• FEATURED

View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Matrix Interpolation

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

#1Phy  Members

Posted 14 April 2005 - 03:08 PM

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.

#2John Schultz  Members

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)).

#3Phy  Members

Posted 14 April 2005 - 06:37 PM

Well I've tried to do it wih quaternions and axis-angles, but it looks like im toying with glScale on different axis :( I don't know what I'm doing wrong either.

#4dodecahedron  Members

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.

#5scgames  Members

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).

#6John Schultz  Members

Posted 15 April 2005 - 08:13 AM

Quote:
 Original post by jykHere'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

#7Phy  Members

Posted 15 April 2005 - 10:45 AM

Thanks guys, that did it!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.