Get Scale Factor From A Matrix

Started by
4 comments, last by Zakwayda 16 years ago
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.
Advertisement
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.
The scaling factor is just the determinant of the matrix.
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.
Quote:Original post by emeyex
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.


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.
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)

This topic is closed to new replies.

Advertisement