Skip to main content
GameDev.net gamedev.net
🔒 Locked

how to interpolate a matrix

Started by ehmdjii Jun 23, 2010 at 2:57 AM 3 replies 2.7k views
Original Post
ehmdjii
ehmdjii
hello,

i store the position of an object in 3d space in a 4by4 transformation matrix. now in order to move the object from the position stored in matrix A to the position stored in matrix B, i would like to interpolate them.

so do i just do this by interpolating each of the 16 values in the matrix, or do i have to take special care about something?

thanks!
macnihilist
macnihilist
If you really only want to move the object (only translation in matrices is different) this will work. But in general interpolating the matrix coefficients will not work (unless maybe the keyframes are _very_ close to one another).
AFAIK, the best way to do this is to decompose you matrix into
* position
* orientation (quaternion)
* scale
interpolate these separately and then combine them into a matrix again.
The main problem with interpolating matrices that describe a transformation is the orientation part.
If you interpolate the coefficients in the matrix you interpolate the basis vectors of the coordinate frame, which can distort the space heavily.

If, however, you are really bound to interpolate matrices for some mysterious reason, there are techniques to do this, too.
(And most of the time they work surprisingly well.)
Some papers:
* "Keyframing Using Linear Interpolation of Matrices" by Amy Hawkins
* "Linear Combination of Transformations" by Mark Alexa
!!BUT!! Be sure you read this also:
* "Errors and Omissions in Marc Alexa's 'Linear Combination of Transformations'" by Charles Bloom
Living
Living
Hello!

If you only wanted to interpolate the translation, you just need to interpolate the translation part of the 4by4 matrix.

If you wanted to interpolate all of the translation, scale and rotation, you need to change the 4by4 matrix to 1by3 vector(presented translation), 1by3 vector(presented scale) and a quaternion(presented rotation).

A 4by4 matrix is primarily made by a vector(have 3 elements) and a 3by3 matrix(this contain rotation info and scale info).

In left hand system, the 4by4 matrix can be presented like this:
M 0 // M is 3by3 matrix, T is 3by1 vector
T 1

If you just wanted to interpolate the translation, you just need to interpolate vector T.


If you wanted to know more about these, I suggest you to read the book called "3D math primer for graphics and game development".
haegarr
haegarr
Quote:
Original post by Living
In left hand system, the 4by4 matrix can be presented like this:
M 0 // M is 3by3 matrix, T is 3by1 vector
T 1
Yes it can be, but there is no relationship to left-handedness; it can also be used for right-handedness as well. In fact, the structure of the matrix shows that
(a) row vectors are in use (due to the fact that the homogeneous part is a column), and
(b) the homogeneous part is 4th component.
Both are conventions.
Emergent
Emergent
So you want to interpolate from (R1, d1) to (R2, d2), where R1,R2 are rotation matrices and d1,d2 are vectors (it's clear that these pairs are "the same thing" as 4x4 homogeneous matrices, right?). Here's the natural way to do that:

Let,
R12 = R2 R1^T
r12 = logSO3(R12).

Then the interpolated values are

R(t) = expSO3(r12 t) R1
d(t) = (1 - t) d1 + t d2 .

See Wikipedia here for a description of the logSO3 and expSO3 functions.

The functions R,d will satisfy,
- (R(0), d(0)) = (R1,d1)
- (R(1), d(1)) = (R2,d2)
- R(t) is always a rotation matrix
(If you want this to take more than one second or start at a time other than t=0, rescale time as appropriate in the above.)

Explanation: A 3x3 rotation matrix together with a 3-dimensional vector represents a rigid body displacement, and the set of all these pairs is a manifold called SE(3). The interpolant I gave you is a geodesic on SE(3), meaning that it takes the shortest path on the manifold from (R1,d1) to (R2,d2).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.