Czy można zamienić trójwymiarową macierz obrotu (4x4) na jej części składowe (obrót, skalę itp.)?

11

Aby być bardziej konkretnym, pracuję nad aplikacją na iOS i mam CATransform3Dstrukturę (w zasadzie tablicę transformacji 4x4).

Czy można wywnioskować wszystkie „operacje”, które pociąga za sobą ta matryca? Rzeczy takie jak obrót, skala itp. Implikuje?

elsurudo
źródło

Odpowiedzi:

10

Macierz można rozkładać na podstawowe transformacje: translację, skalowanie i obrót. Biorąc pod uwagę tę macierz:M=TRS

M.=[za00za01za02za03za10za11za12za13za20za21za22za230001]

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 S1 to get R

(RS)S1=[a00a01a02a10a11a12a20a21a22][s0000s1000s2]1=[a00a01a02a10a11a12a20a21a22][1/s00001/s10001/s2]

Thus ((RS)S1=RI=R):

R=[a00/s0a01/s1a02/s2a10/s0a11/s1a12/s2a20/s0a21/s1a22/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).

user5488
źródło
2
Can you clarify what the problems with floating-point precision are? I don't see anything in this method that would cause precision problems, unless the scale is really extreme. Also, worth noting that this method may fail if the matrix was composed from a sequence of matrices that includes both non-uniform scales and rotations. The R matrix will turn out not to be a rotation in that case, but will include some shear.
Nathan Reed
2
All floating point numbers have intrinsic (bounded) error. Any time you perform operations, and particularly addition or subtraction, you compound the error, increasing the magnitude of the bounds. Hidden in the decomposition algorithm are many addition operations (both in the matrix multiplication and the scale magnitude calculation) and a square root (in the scale). Further decomposition will introduce further error.
Timbo
1
@Timbo There isn't any full matrix multiplication here though, just multiplying the columns of the matrix by the inverse scales. And a vector magnitude involves adding all positive quantities, so there's no catastrophic cancellation there; it doesn't produce much relative error, AFAICT. Anyway, the author clarified that they're talking about further decomposing the rotation matrix into Euler angles or suchlike, which makes more sense.
Nathan Reed
Thanks – great answer. Follow-up: to get the original matrix back, I am assuming we need to follow a certain order of operations, starting from the identity matrix. Would this order be TRS?
elsurudo