Jump to content

  • Log In with Google      Sign In   
  • Create Account

Smooth interpolation between two matrices


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.

  • You cannot reply to this topic
9 replies to this topic

#1 nikitablack   Members   -  Reputation: 614

Like
0Likes
Like

Posted 01 October 2012 - 04:24 AM

Hi. I have two 2D matrices with scale, rotation, skew, translation. How can I interpolate between them. Say, I want to know matrix at time 0.5. I know it's possible because tools such as Flash IDE can construct intermediate frames based on start and end frames.

Sponsor:

#2 rnlf   Members   -  Reputation: 1185

Like
2Likes
Like

Posted 01 October 2012 - 04:35 AM

If you *really* want to interpolate the matrices, it will (as you seem to have noticed) look funny. What you really want to do, is to interpolate all components on their own and reconstruct the resulting matrix afterwards. For rotation interpolation, have a look at quaternions and the SLERP interpolation scheme. Translation and scale can be interpolated using standard linear interpolation. Don't know about skew though, I never actively used it...

my blog (German)


#3 nikitablack   Members   -  Reputation: 614

Like
0Likes
Like

Posted 01 October 2012 - 04:53 AM

Yes, I meant interpolation of "states", i.e. rotation, scale etc. Since it's 2D I don't need quaternions. And yes, the trickiest part for me is to deal with shear. I investigate bit deeper and found that tool that I use (Flash IDE) use strange skew matrix algorithm. So the problem for me is to decompose correct values. And I think this forum can't help me in this particular question. So, thanks everyone :).

#4 Ashaman73   Crossbones+   -  Reputation: 8001

Like
0Likes
Like

Posted 01 October 2012 - 05:37 AM

Since it's 2D I don't need quaternions.

If you want to do spherical interpolation (rotation), then you should use quaternions. A 2d space is just a plane in a 3d space, therefore you can use 3d math (just set one component to zero).

#5 nikitablack   Members   -  Reputation: 614

Like
1Likes
Like

Posted 01 October 2012 - 06:16 AM

Yes, but it's a pointless exhaustion of system resources. In 2D interpolation is simple
startAng + (endAng - strtAng) * t
so you can't persuade me to use quaternions :).

BTW I solve a problem. Flash uses it's own skew matrix. I found an algorithm. Flawless victory.

#6 Zouflain   Members   -  Reputation: 532

Like
0Likes
Like

Posted 01 October 2012 - 06:16 AM

Darn, beaten to the punch (I arrived rather late). Slerp and quaternions are so ludicrously simple that it makes my head hurt thinking about how much my head originally hurt when I'd convinced myself it was something hard! You should definitely get used to them, as familiarizing yourself with quaternions will make more than just (rotation) matrix interpolation easier. Also, quaternions work in 2D just as well as 3 (after all, the Z component will only change if the two control points have different z components which isn't the case in your model).

Also note that you can't directly interpolate rotation matrices - or, well, you can but it's ugly. If you don't care about smooth interpolations, then you can always do a (1.0-A)*M1+A*M2 [where 0<=a<=1] linear interpolation... but that's horrid for just about any practical use for rotation matrices. As for your translation and scale, that can be linearly interpolated without much concern.

Oof, I just realized all this was said above. Still, it's good info.

#7 MashesButtons   Members   -  Reputation: 107

Like
-1Likes
Like

Posted 01 October 2012 - 08:35 AM

Using a linear interpolation between two angles will result in something that looks off, even if it's for 2D space. If people could linearly interpolate theta and have it look correct, then they could linearly interpolate phi as well.

#8 Álvaro   Crossbones+   -  Reputation: 13934

Like
0Likes
Like

Posted 01 October 2012 - 09:15 AM

Linear interpolation of angles in 2D gets a bit tricky when you want to go from 10 degrees to 350 degrees. If you do it naively, you'll go around the long end.

The true analog of quaternions for 2D rotations is complex numbers. Just as with quaternions, rotations are represented by unit-length complex numbers, and you can slerp between them just fine. The conversion from angle to complex number is cos(alpha)+sin(alpha)*i. When you want to apply the rotation to a point (x,y), interpret the point as x+y*i and multiply it by the complex number.

#9 luca-deltodesco   Members   -  Reputation: 637

Like
0Likes
Like

Posted 01 October 2012 - 10:09 AM

Of course, in 2D you often have cases where you don't restrict yourself to one rotation, and you wish to interpolate between -pi rad and 11pi rad doing several full rotations as part of it.

#10 Álvaro   Crossbones+   -  Reputation: 13934

Like
0Likes
Like

Posted 01 October 2012 - 11:17 AM

Of course, in 2D you often have cases where you don't restrict yourself to one rotation, and you wish to interpolate between -pi rad and 11pi rad doing several full rotations as part of it.


That can be done in 3D as well, but it's not a commonly desired behavior. When it is, chances are the situation is best described by an initial attitude and an angular velocity to be integrated. This also works in 2D.

Edited by alvaro, 01 October 2012 - 11:17 AM.





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.



PARTNERS