NDIR 189 Report post Posted February 24, 2010 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? 0 Share this post Link to post Share on other sites
jyk 2094 Report post Posted February 24, 2010 Quote:Original post by NDIRHey 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. 0 Share this post Link to post Share on other sites
NDIR 189 Report post Posted February 24, 2010 Excellent, thanks. Do you by any chance have some matrix slerp explanation links at hand? 0 Share this post Link to post Share on other sites
Deliverance 387 Report post Posted February 24, 2010 Quote:Original post by NDIRExcellent, 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=318138quote 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! 0 Share this post Link to post Share on other sites
Steve132 433 Report post Posted February 24, 2010 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' 0 Share this post Link to post Share on other sites
Emergent 982 Report post Posted February 24, 2010 @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). 0 Share this post Link to post Share on other sites
jyk 2094 Report post Posted February 25, 2010 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). 0 Share this post Link to post Share on other sites
NDIR 189 Report post Posted February 25, 2010 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] 0 Share this post Link to post Share on other sites
Emergent 982 Report post Posted February 25, 2010 Quote:Original post by NDIRAnother 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. 0 Share this post Link to post Share on other sites
NDIR 189 Report post Posted February 25, 2010 Thanks, Gram-Schmidt will do for now since my rotation matrices will be reset every now and then. 0 Share this post Link to post Share on other sites
NDIR 189 Report post Posted February 25, 2010 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. 0 Share this post Link to post Share on other sites