If I have a matrix from scale, translate, and rotation transform. I want to split 开发者_高级运维this matrix to two matrix. One is rotation+translation matrix, the other is scale matrix.
Because I want to compute the correct normal vector transform, so I only need orthogonal matrix to do the computation for surface normal vector
Any ideas?
If I have a matrix from scale, translate, and rotation transform. I want to split this matrix to two matrix. One is rotation+translation matrix, the other is scale matrix.
I'm assuming this matrix you are talking about is a 4x4 matrix that is widely used by some, widely despised by others, with the fourth row being 0,0,0,1.
I'll cause these two operations "scale" and "rotate+translate". Note well: These operations are not commutative. Scaling a 3-vector and then rotating/translating this scaled vector yields a different result than you would get by reversing the order of operations.
Case 1, operation is "rotate+translate", then "scale".
Let SR=S*R, where S is a 3x3 diagonal matrix with positive diagonal elements (a scaling matrix) and R is a 3x3 orthonormal rotation matrix. The rows of matrix SR will be orthogonal to one another, but the columns will not be orthogonal. The scale factors are the square root of the norms of the rows of the matrix SR.
Algorithm: Given 4x4 matrix A, produce 4x4 scaling matrix S, 4x4 rotation+translation matrix T
A = [ SR(3x3) Sx(3x1) ]
[ 0(1x3) 1 ]
- Partition A into a 3x3 matrix SR and a 3 vector Sx as depicted above.
- Construct the scaling matrix S. The first three diagonal elements are the vector norms of the rows of matrix SR; the last diagonal element is 1.
- Construct the 4x4 rotation+translation matrix T by dividing each row of A by the corresponding scale factor.
Case 2, operation is "scale", then "rotate+translate".
Now consider the case RS=R*S. Here the columns of A will be orthogonal to one another, but the rows will not be orthogonal. In this case the scale factors are the square root of the norms of the columns of the matrix RS.
Algorithm: Given 4x4 matrix A, produce 4x4 rotation+translation matrix T, 4x4 scaling matrix S
A = [ RS(3x3) x(3x1) ]
[ 0(1x3) 1 ]
- Partition A into a 3x3 matrix RS and a 3 vector x as depicted above.
- Construct the scaling matrix S. The first three diagonal elements are the vector norms of the columns of matrix RS; the last diagonal element is 1.
- Construct the 4x4 rotation+translation matrix T by dividing each row of A by the corresponding scale factor.
If the scaling is not uniform (e.g., scale x by 2, y by 4, z by 1/2), you can tell the order of operations by looking at the inner products of the rows and columns of the upper 3x3 matrix with one another. Scaling last (my case 1) means the row inner products will be very close to zero but the column inner products will be non zero. Scaling first (my case 2) reverses the situation. If the scaling is uniform there is no way to tell which case is which. You need to know beforehand.
Just an idea -
- Multiply the matrix by the unit vectors
(1/sqrt(3),1/sqrt(3),1/sqrt(3))
, - check how the length of the vector after the multiplication,
- scale the matrix by the reciprocal of that value. Now you have an orthogonal matrix
- create a new scale matrix with the scale you found.
- Remove the translation to get a 3x3 matrix
- Perform the polar decomposition via SVD.
精彩评论