Sign in to follow this  

matrix interpolation

This topic is 2848 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, this is the problem i have: I have 2 matrices3x3. One was created by multiplying several X,Y,Z rotational matrices. The second matrix is generated from angle and axis (rotation about custom axis). Now i'd like to interpolate from first to second matrix in N steps. How would i do that?

Share this post


Link to post
Share on other sites
Quote:
Original post by NDIR
Hey all,

this is the problem i have:

I have 2 matrices3x3. One was created by multiplying several X,Y,Z rotational matrices. The second matrix is generated from angle and axis (rotation about custom axis).


Now i'd like to interpolate from first to second matrix in N steps. How would i do that?
As long as each matrix represents a pure rotation, it doesn't really matter how they were generated. As for interpolating the matrices, there are a few different options, but SLERP (spherical linear interpolation) would probably be the most obvious choice. You can apply the SLERP algorithm directly to the matrices, or convert the matrices to quaternions and use the quaternion form of SLERP (which is a bit more elegant and efficient than the matrix version) instead.

Share this post


Link to post
Share on other sites
Quote:
Original post by NDIR
Excellent, thanks. Do you by any chance have some matrix slerp explanation links at hand?


Here's a link:

http://www.gamedev.net/community/forums/topic.asp?topic_id=318138

quote from the link:

"If you're asking about matrix slerp, you can slerp two matrices A and B by finding the matrix that rotates A to B, extracting the axis and angle from this matrix, scaling the angle, recomposing the axis and scaled angle into a new matrix, and multiplying this matrix with A to get your result. It works fine, but it's obviously a lot less efficient than quaternion slerp."

Finding a rotation from A to B, means finding a basis change matrix from A to B. Because A and B are rotation matrices this can be easily written like : inverse(A)*B or equally transpose(A) * B. A takes us from world space to A's own coordinate frame, the inverse takes us from A to world space and from there we go directly to B's space.

Hope this is right and it helps!

Share this post


Link to post
Share on other sites
Another way that I really like: since the exponential of a skew-hermitian matrix A is always an orthonormal rotation matrix, the logarithm of an orthonormal (rotation) matrix O is a skew-symmetric matrix, which is linearly interpolatable directly. To interpolate between two orthonormal matrices O1 and O2, by a parameter a, to get an orthonormal matrix Oi, do this:

Oi = exp((1-a)*log(O1)+a*log(2))


Implementing the exp(O) and log(O) operations on matrices is very easy: Simply take the eigenvalue decomposition of your matrix O=Q*E*Q' (which any decent matrix library can do), then, log(O)=Q*log(E)*Q', and exp(O)=Q*exp(O)*Q'

Share this post


Link to post
Share on other sites
@NDIR: I'd just go with Deliverance's answer: Convert the relative rotation to axis-angle representation and interpolate the angle. That's the easiest way to understand what's going on if you're new to this.

Quote:
Original post by jykYou can apply the SLERP algorithm directly to the matrices, or convert the matrices to quaternions and use the quaternion form of SLERP (which is a bit more elegant and efficient than the matrix version) instead.


To pick nits, you wouldn't really be applying SLERP to the matrices per-se (since rotations do not lie on a sphere in GL(n)); you'd just generally be doing geodesic interpolation). SLERP is related to rotations only insofar as rotations can be represented as (equivalence classes of) points on a sphere in 4-space as quaternions -- so geodesic interpolation is SLERP only when you're using that particular embedding...

Quote:
Original post by Steve132Another way that I really like: since the exponential of a skew-hermitian matrix A is always an orthonormal rotation matrix, the logarithm of an orthonormal (rotation) matrix O is a skew-symmetric matrix, which is linearly interpolatable directly.


I'm a big fan of the matrix Lie algebra interpretation also. That said, you need to be careful with your complex logarithms, since there are multiple reasonable ways to define the complex logarithm (since the complex exponential doesn't actually have a unique inverse).

Share this post


Link to post
Share on other sites
Quote:
To pick nits, you wouldn't really be applying SLERP to the matrices per-se (since rotations do not lie on a sphere in GL(n)); you'd just generally be doing geodesic interpolation). SLERP is related to rotations only insofar as rotations can be represented as (equivalence classes of) points on a sphere in 4-space as quaternions -- so geodesic interpolation is SLERP only when you're using that particular embedding...
No, you're right, that's a good point - I should have said 'the matrix equivalent of quaternion SLERP' (equivalent in the sense that it has the same end result, just using a different representation).

Share this post


Link to post
Share on other sites
Another question in matrix context.

I'm facing a problem when too many multiplications of rotation matrices start to deform the object. Probably because the computational error accumulates over multiplications? Is there a way to fix this? Some sort of matrix normalization?

Is it enough to simply normalize each row?

[Edited by - NDIR on February 25, 2010 1:56:20 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by NDIR
Another question in matrix context.

I'm facing a problem when too many multiplications of rotation matrices start to deform the object. Probably because the computational error accumulates over multiplications? Is there a way to fix this? Some sort of matrix normalization?

Is it enough to simply normalize each row?


No, that's not enough, because you also need to make sure that the rows (or columns) are all orthogonal.

What you really want is the matrix polar decomposition. You throw out the non-unitary part. This gives you the pure rotation matrix closest to the matrix you have.

You can also get away with just doing Gram-Schmidt on the columns (or rows) of the matrix; this will give you a pure rotation which should be close, though it's not necessarily optimal in any way.

This is one advantage to the quaternion representation; they're easy to normalize.

Share this post


Link to post
Share on other sites
As for the interpolation.

I followed the jyk hint. Then i remembered that i use excelent! CML in all of my c++ projects. But the problem here is that for this project i use java. So i simply ported c++ cml slerp code into java and made it compatible with vecmath.

Share this post


Link to post
Share on other sites

This topic is 2848 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this