Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

HI I am wondering if there is a unique matrix that maps $(x_1,y_1,z_1)$ into $(x_2,y_2,z_2)$. These two vectors have equal magnitude and are defined in orthogonal 3-D basis. If there is a unique solution how can I find it by considering rotation about all three orthogonal basis?

share|improve this question

5 Answers 5

No, but if you provide two direction wedges, where the two wedges have identical angular width, you can find the unique 3x3 matrix rotator that transforms the input wedge into the output wedge.

What is a direction wedge? It is an ordered pair of direction vectors, d1 d2. Each is a 3D direction vector (a unit vector used to represent pointing direction in 3D space). A 3D direction vector is equivalent to a point on the unit sphere [ x, y, z]. There is a 1:1 mapping of directions in 3-space to points on the unit sphere, thus to its numerical representation as a unique point on that sphere. This is highly advantageous for algorithmic development, as the exception cases (singularity, ambiguity, discontinuity) are avoided, while achieving symmetry among the x-y-z features. There is only one point in 3D lacking a direction (the origin).

Back to wedges. What is an example of a wedge? It's just an ordered pair of two distinct directions. You could be standing on the shoreline in San Francisco, and measure the directions to the two suspension peaks of the Golden Gate Bridge. To make a wedge, you just need to be clear about their order...[ dir_south_peak, dir_north_peak ]. Those two directions form a 3D pie wedge going out from where you are standing. The only restriction on d1 and d2 is they may not be coincident or opposite directions. Another way to say this is, the angle subtended between the two directions is bracketed: 0 < angle < 180.

OK, now here's an interesting problem you can solve with this wedge. Suppose you have a camera-equipped drone or chopper at your same location. You want to determine the 3D orientation of this flying platform, and gyros are way too expensive. How can you build a camera-based software gyro?

Let's say the drone's camera is wide-angle or even a full hemispherical camera, so that it can "see" the two peaks of the Golden Gate Bridge. This camera system has its own local platform axis system x-y-z which differs from the ground X-Y-Z axes by some unknown, arbitrary 3D rotation. The ground X-Y-Z axes are reference axes X=[1 0 0], Y=[0 1 0], Z=[0 0 1]. You want to determine the value of the platform's x-y-z axes expressed as 3 orthogonal direction vectors in the reference coordinate system. That is a great way to represent the 3D orientation of the drone - they'll only be one unique numerical representation for one spatial orientation! Something you're not going to achieve with Euler angle triplet [ roll angle, pitch angle, yaw angle].

OK, so platform's x-y-z axes orientation is the unknown which we want to solve. We have the bridge peak wedge measurements [d1, d2] in reference coordinates. The 2nd wedge we need is obtained by having the drone camera measure the directions to the same two peaks. The angular width of the wedge will be the same. But the two directions will be different. They will both be "off" from the corresponding reference directions by the orientation of the drone camera. Let's call these two directional measurements [d1, d2]cam.

So now we have 2 wedges: [d1, d2 ] (bridge peak directions measured in reference coordinates) [d1, d2]cam (bridge peak directions measure by camera having unknown orientation x-y-z)

How do we solve for x-y-z?

This is called the Rotational Inference Algorithm. I need graphics to explain it, so it doesn't appear here. It is published here: http://spie.org/Publications/Proceedings/Paper/10.1117/12.611602

The short and skinny is that the orientation of the platform, R = [x-y-z] can be computed as:

R1 = rotator [ d1 -- (d1 x d2)norm ] (-- the y axis is determined by the x and z axes)

R2 = rotator [ d1cam -- (d1cam x d2cam)norm ]

R = R1 • inverse(R2)

Long answer, but everyone should be aware that you can build a 3D gyro out of a wide-field camera and a software number-crunching algorithm. All you need are two stable, known directional beacons that the camera can latch onto and process.

share|improve this answer


For example, let $p_1 = (x_1,y_1,z_1)^T$, and $d_1 = (x_2,y_2,z_2)^T$. Choose $p_2,p_3 \in \mathbb{R}^3$ so that $p_1, p_2, p_3$ are orthogonal. Let $d_2, d_3$ be arbitrary. Then define the matrix $$A = \frac{1}{\|p_1\|^2} d_1 p_1^T + d_2 p_2^T + d_3 p_3^T $$

It is easy to check that $A p_1 = d_1$. Since $d_2, d_3$ are arbitrary, it is clear that the transformation that maps $p_1$ into $d_1$ is not unique.

In fact, all transformations $A$ that satisfy $A p_1 = d_1$ can be expressed in this form with appropriate choice of $d_2,d_3$. If the $p_k$ and $d_k$ are chosen to be orthonormal, then the resulting $A$ will be a rotation (possibly improper).

share|improve this answer

In the following, c stands for cosine and s for sine (of any angle $\theta$) $$\pmatrix{c & s\\ -s &c} \pmatrix{x_1 \\ y_1}$$ So in particular, we have that $s^2 + c^2 = 1$. The matrix multiply represents the rotation about the z-axis. The magnitude of the vector is preserved as such: $$\left|\pmatrix{x_1 \\ y_1}\right|^2 = x_1^2 + y_1^2 \quad \text{this is the original magnitude}$$ $$\left|\pmatrix{cx_1 +sy_1\\ -sx_1 + cy_1}\right|^2 = (cx_1 +sy_1)^2 + (-sx_1 + cy_1)^2$$ $$=(c^2x_1^2+s^2y_1^2+2csx_1y_1) +(s^2x_1^2+c^2y_1^2-2csx_1y_1)$$ $$=c^2(x_1^2+y_1^2)+s^2(x_1^2+y_1^2)$$ $$=(c^2+s^2)(x_1^2+y_1^2)$$ $$=x_1^2+y_1^2 \quad \text{and the magnitude is unchanged}$$

You can apply this form of matrix a few times, starting with your first point in 3-D, and reach the desired value in one coordinate at a time. So for example, to rotate about the y axis: $$\pmatrix{c & 0& s\\0&1&0\\-s&0&c}\pmatrix{x \\ y \\ z}$$ You would only need to do this twice, as the final value would by necessity match as desired, since the magnitudes are the same for the two points.

To find c and s, use $$c=\frac{x_1}{\sqrt{x_1^2+y_1^2}} \quad\text{and}\quad s=\frac{y_1}{\sqrt{x_1^2+y_1^2}}$$

HINT: any two values instead of $x_1$ and $y_1$ in that formula gives a valid c and s for a rotation matrix.

share|improve this answer

coffeemath explained why you cannot find an unique such matrix.

On another hand, since you are interested in rotations about the axes, there exists a pair of rotations $R_1, R_2$ about two of the axes of your choices, so that $v_2=R_2 R_1 v_1$. Moreover, if you fix the axes, and the order, I think there are exactly two such rotations.

To understand why, just think in spherical coordinates, where the angles are expressed with respect to the two axes you chose...

Then the first vector is $(R, \phi_1, \theta_1)$ and the second vector is $(R, \phi_2, \theta_2)$, so a rotation if angle $\phi_1-\phi_2$ and one of angle $\theta_1-\theta_2$ should do it.

The second possibility comes from the fact that you can also do a rotation of more than $180^\circ$ with respect to the second angle....

share|improve this answer
Suppose your choice is to rotate around x axis, then around y axis. And suppose v_1 is close to the unit vector for the x axis, while v_2 is close to the unit vector for the y axis. Then after a rotation around the x axis, we arrive at a vector w which is still near the unit vector of the x axis. When such a vector is rotated around the y axis it cannot end up near the goal vector v_2. The rotation about the y axis will preserve whatever angle w now makes with the y axis. –  coffeemath Oct 10 '12 at 2:12
I think the spherical coordinate approach makes it clear one can use first a rotation about the z axis, and then one more rotation. However, once the rotation about the z axis has been done, in such a way as to change the longitude of v_1 to that of v_2 (arriving at say w) there is another rotation to go. In order to now rotate w into v_2 typically the origin, w, and v_2 make a plane, and the second rotation must be around the perpendicular to that plane, which is not typically one of the three axes (x or y or z). –  coffeemath Oct 10 '12 at 2:29

There are many such matrices. If you find a single matrix $M$ which maps $v_1=(x_1,y_1,z_1)$ to $v_2=(x_2,y_2,z_2)$, then we could multiply such an $M$ by a rotation matrix whose axis goes along $v_2$.

To get a matrix $M$ we can use $M=1/(v_1 * v_1)v_2^t v_1$. Here by $v_1*v_1$ I mean dot product of $v_1$ with itself, and by $v_2^t$ I mean transpose of $v_2$, which would make it into a column vector. That way $v_2^t v_1$ comes out to be a matrix. You have to use $v_1^t$ when computing the result of multiplying $M$ by $v_1$.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.