MATLAB: How to Find the Rotation Matrix

MATLABmatrix

What is the possible solutions for an $3×3$ size orthogonal matrix with the known parameters of the first two columns which makes 6 parameters known?
Let's think of a rotation matrix which is an orthogonal matrix:
R=[r11 r12 r13;
r21 r22 r23;
r31 r32 r33]
The parameters of r11, r21, r31, r12, r22, r32 are known values. And it is desired to find the last (third) column with the parameters of r13,r23,r33.
I take the square root of each raw which is equivalent to 1 unit vector.\
r11^2+r12^2+r13^2=1
r21^2+r22^2+r23^2=1
r31^2+r32^2+r33^2=1
Therefore we can get to the equations of
r13= sqrt(1-r11^2-r12^2)
r23= sqrt(1-r21^2-r22^2)
r33= sqrt(1-r31^2-r32^2)
However, if there is one solution for the rotation matrix of R, how can I find that unique solution. Square root of any raw gives me two solutions.
Whichever (positive/negative square root of r13,r23,r33 I would take, it would be still an orthogonal matrix:
r1^2+r23^2+r33^2=1
So is there one unique solution or multiple solutions?

Best Answer

Hi ercan,
MODIFIED
First of all, for a rotation matrix the two known columns have to be an orthonormal pair, meaning that there are conditions on the initial six variables. If these variables are relabeled as two 3x1 column vectors c1,c2 then
norm(c1) = norm(c2) = 1; dot(c1,c2) = 0
Let's assume that's true.
From your eqns, at first glance it might seem that there could be eight solutions, since you can have +-1 for each of r13,r23,r33. However, the rows have to be orthogonal, so e.g.
r11*r21 + r12*r22 + r13*r23 = 0
If you have a solution, then changing one of r13 or r23 will change the sign of the last term and will not provide a solution. You can change both signs or neither, but not just one. Similarly for the other pairs of rows. The net result is that there are two solutions. One solution is third column equaling the cross product of the first two columns (thus being perpendicular to both of them), and the other solution is simply that solution times an overall minus sign.
However, changing the overall sign in the third column also changes the sign of the determinant of the matrix. As Bruno pointed out, a rotation matrix must have determinant +1. So the only solution is
c3 = cross(c1,c2)
in which case
R = [c1 c2 cross(c1,c2)]
has determinant +1.
Note that for this to come out correctly there is a sign convention present (or one might say, hidden) in the cross function.