# Get Scale Factor From A Matrix

## Recommended Posts

Hello, everyone here! I'm new to 3d programming. I want to extract position, rotation(Quaternion) and scale factor from a matrix. I know position and rotation, but i do not know how to extract scale. Position = ( Matrix._41, Matrix._42, Matrix._41 ); Rotation = QuationFromMatrix( ); Can I get scale from a matrix? Thanks very much.

##### Share on other sites
The length of each of the basis vectors (first 3 row or column vectors, depending on your matrix-style). I.e.,
scale.x = length( m.column(0) );scale.y = length( m.column(1) ); etc...
Where m.column(i) returns a 3-vector. It's worth noting that this will only hold up (I believe) if your matrix has been scaled in its local frame, i.e., no shearing or skewing or other weirdness, such as a scale in the global reference frame after a rotation.

##### Share on other sites
The scaling factor is just the determinant of the matrix.

##### Share on other sites
The determinant of a matrix is a scalar. Perhaps in some other sense that I'm not thinking of, the determinant is the scale factor, but it's certainly not the scale factor for a non-uniformly scaled object; in such a case, the scale factor is a 3-vector, and it can be calculated from the length of the row or column vectors as I mentioned.

##### Share on other sites
Quote:
 Original post by emeyexThe determinant of a matrix is a scalar. Perhaps in some other sense that I'm not thinking of, the determinant is the scale factor, but it's certainly not the scale factor for a non-uniformly scaled object; in such a case, the scale factor is a 3-vector, and it can be calculated from the length of the row or column vectors as I mentioned.

I see what you mean; good call. Actually, I wouldn't have replied to this thread had I seen your original reply, since it was a nice answer. The problem is that I'd loaded the page a while before your reply, and then submitted my post without seeing yours.

At any rate, the determinant tells you how volumes are scaled -- so it's the product of your scaling factors. I suppose that if you were multiplying each component of every vector by some constant k (so the scaling was uniform along each direction), then you'd have det(M)=k^3.

##### Share on other sites
If you extract the quaternion from the matrix as-is, and the matrix incorporates a scaling, then I believe that the resulting quaternion will be incorrect.

To extract the scale, rotation, and translation from a matrix representing the series of transforms S->R->T:

1. Compute the scaling factors as the magnitudes of the first three basis vectors (columns or rows) of the matrix
2. Divide the first three basis vectors by these values (thus normalizing them)
3. The upper-left 3x3 part of the matrix now represents the rotation (you can use this as is, or convert it to quaternion form)
4. The translation is the fourth basis vector of the matrix (in homogeneous coordinates - it'll be the first three elements that you're interested in)

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628308
• Total Posts
2981973

• 9
• 13
• 11
• 12
• 11