Macierz można rozkładać na podstawowe transformacje: translację, skalowanie i obrót. Biorąc pod uwagę tę macierz:M=TRS
M = ⎡⎣⎢⎢⎢za00za10za200za01za11za210za02za12za220za03za13za231⎤⎦⎥⎥⎥
Możesz dekomponować tłumaczenie przez inspekcję, używając ostatniej kolumny .t=(a03,a13,a23)
Do skalowania wiemy, że pierwsze trzy kolumny macierzy odpowiadają bazom (osiom). Skalę możemy uzyskać na podstawie długości / normy tych wektorów, tj. Ile skalowano podstawy. Skala jest więc gdzie:s=(s0,s1,s2)
s0=∥(a00,a10,a20)∥s1=∥(a01,a11,a21)∥s2=∥(a02,a12,a22)∥
Now you have the scale, you can get rid of it using the 3×3 sub-matrix that corresponds to RS by multiplying the matrix with the inverse of the scale S−1 to get R
(RS)S−1=⎡⎣⎢a00a10a20a01a11a21a02a12a22⎤⎦⎥⎡⎣⎢s0000s1000s2⎤⎦⎥−1=⎡⎣⎢a00a10a20a01a11a21a02a12a22⎤⎦⎥⎡⎣⎢1/s00001/s10001/s2⎤⎦⎥
Thus ((RS)S−1=RI=R):
R=⎡⎣⎢a00/s0a10/s0a20/s0a01/s1a11/s1a21/s1a02/s2a12/s2a22/s2⎤⎦⎥
This is the final rotation matrix. You can further decompose it using many ways. It is quit lengthy but you can search for decomposing a rotation matrix.
This method only gives an equivalent values in the form of translation, scaling and rotation (the original matrix maybe the result of other types of transformations). It may has problems with floating point precision with the rotation angles if you further used the decomposed angles, rounding errors may accumulate in the computations. You should not use it unless you did not construct the matrix yourself.
If you are the one who constructed the matrix and wanted the decomposition in order to be able to edit and display the translation, scale and rotation individually and independently, probabbly the cleanest why is to store the components of t, s and r in a transform class individually as vectors (maybe quaternion for the rotation). Only when you need the transform matrix, construct a TRS matrix from these components (You can cache the matrix until some component is changed).