# decomposing an affine transformation matrix

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

## Recommended Posts

Hello, in my modelling format (.x) there are 4x4 matrices for the skeletal animation of the bones. So I think they are affine transformation matrices. I need to decompose these into translation, rotation and scaling components. I did some googling but didn't find a working algorithm or source code. Could somebody point me in the right direction and tell me what's the exect term to search for or even how this is done? I would naivly just take the 4th colum as the translation component and the upper left 3x3 part might be the rotation*scaling. So When rotating the 3 axis vectors and looking how their length has changed would give me the scaling factors that need to be removed from the 3x3 matrix to get the pure rotation component that I can convert to a quaternion. Any suggestion or hints welcome :-) Regards, Markus

##### Share on other sites
Ken Shoemake's Polar Decomposition (book: Graphics Gems IV):
Source code, see decomp_affine().
Paper.

##### Share on other sites
Thank you. Seems to be what I'm looking for. I've not enough time to read the paper thoroughly but I've got 2 questions about the source code:

What's this "stretch rotation" quaternion for? Can I just take the translation, scaling factors, essential rotation and interpolate the first two linearly, the last by angle? Is this "stretch rotation" a concatenated rotation and scaling?

##### Share on other sites
I don't know if this will help, but I posted a solution to the special case of scale->rotate>translate in this thread. Note that I haven't tested this yet so I can't guarantee its correctness.

I think the example in the thread refers to a D3D matrix, so you'll have to transpose the solution if you're using column vectors.

##### Share on other sites
Quote:
 Original post by muhkuhThank you. Seems to be what I'm looking for. I've not enough time to read the paper thoroughly but I've got 2 questions about the source code:What's this "stretch rotation" quaternion for? Can I just take the translation, scaling factors, essential rotation and interpolate the first two linearly, the last by angle? Is this "stretch rotation" a concatenated rotation and scaling?

In practice, the quaternions are interpolated (lerp, slerp, squad, etc.), and the vectors are lerp'd. The interpolated values are then converted back into an affine matrix. decomp_affine() is used in 3DSMax (see the SDK docs for more info):

Quote:
 For a full discussion of this decomposition see Graphics Gems IV - Polar Matrix Decomposition by Ken Shoemake. ISBN 0-12-336155-9.T F R U K U'T - translation matrixF - either an identity matrix or negative identity matrixR - rotation defined by Quat q.U - rotates you into the coordinates system where the scaling or stretching is doneK - scaling matrixU' - inverse of u.

Quote:
 With the assistance of Polar Decomposition, a non-singular4 × 4 homogeneous matrix M can be factored intomeaningful primitive components, asM = PTRNS,where P is a simple perspective matrix, T is a translationmatrix, R is a rotation matrix, N is ±I, and S is a symmetricpositive definite stretch matrix. The stretch matrix canoptionally be factored, though not uniquely, as UKUT,where U is a rotation matrix and K is diagonal and positive.For a 4×3 affine matrix the perspective factor can bedropped; and for a 3×3 linear matrix, so can the translation.Also, N can be multiplied into S if desired.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 9
• 15
• 14
• ### Forum Statistics

• Total Topics
634070
• Total Posts
3015332
×