Find a unit vector from angles it makes with two other vectors

61 Views Asked by At

Suppose I have two vectors, $\textbf{x}_1$ and $\textbf{x}_2$; How do I find a unit vector, $\textbf{u}$, that makes angles $\theta_1$ and $\theta_2$ respectively with the originally mentioned vectors, $\textbf{x}_1$ and $\textbf{x}_2$?

For what it's worth, I consider all three vectors to originate from the same point. Intuitively, I see that the locus of vectors that make an angle with another vector is a cone, and hence the required unit vector will lie in the intersection of the two cones, which can be at most two vectors. I would like to have them both for my use case.

I used the following Mathematica code to find them, but I find this approach ugly.

Solve[Arccos[Normalize[x1].u]==theta1 && Arccos[Normalize[x2].u]==theta2 && Norm[u]==1, u]

Is there a more straightforward way?

1

There are 1 best solutions below

2
On BEST ANSWER

As you mentioned, the solutions for $\mathbf{u}$ are the intersections of the two cones whose axes are the vectors $\mathbf{x_1}$ and $ \mathbf{x_2}$.

To find these intersections, express the surface of the first cone, whose semi-vertical angle is $\theta_1$, as follows:

We can assume that $\mathbf{x_1}$ is a unit vector (if it not then normalize it), and let $\mathbf{w_1}$ and $\mathbf{w_2}$ be orthogonal to $\mathbf{x_1}$ and to each other, i.e.

$ \mathbf{w_1} \cdot \mathbf{x_1} = \mathbf{w_2} \cdot \mathbf{x_2} = \mathbf{w_1} \cdot \mathbf{w_2} = 0 $

One way to find a pair $\mathbf{w_1},\mathbf{w_2}$ is using spherical coordinates. Express the unit vector $\mathbf{x_1}$ in spherical coordinates

$ \mathbf{x_1} = ( \sin \theta \cos \phi, \sin \theta \sin \phi, \cos \theta)$

Then

$ \mathbf{w_1} = (\cos \theta \cos \phi, \cos \theta \sin \phi, - \sin \theta )$

$ \mathbf{w_2} = ( - \sin \phi, \cos \phi, 0 ) $

Vectors on the cone whose axis is vector $\mathbf{x_1}$ and whose semi-vertical angle is $\theta_1$ are given be

$ \mathbf{u} = [\mathbf{w_1}, \mathbf{w_2}, \mathbf{x_1} ] \begin{bmatrix} \sin \theta_1 \cos \alpha \\ \sin \theta_1 \sin \alpha \\ \cos \theta_1 \end{bmatrix} $

Now we want $\mathbf{u}$ (which is a unit vector also) to make an angle of $\theta_2$ with the unit vector $\mathbf{x_2}$, so we have the following equation for $\alpha$

$ \mathbf{x_2} \cdot \mathbf{u} = \cos \theta_2 $

Expanding the left hand side,

$ A \cos \alpha + B \sin \alpha + C = \cos \theta_2 \hspace{25pt}(1)$

where

$ A = \mathbf{x_2} \cdot \mathbf{w_1} \ \sin \theta_1 $

$ B = \mathbf{x_2} \cdot \mathbf{w_2} \ \sin \theta_1 $

$ C = \mathbf{x_2} \cdot \mathbf{x_1} \ \cos \theta_1 $

Now all we have to do is solve equation $(1)$ for $\alpha$, and this will give two values for $\alpha$, and hence we get two possible vectors $\mathbf{u} $.

The solution of equation $(1)$ is

$ \alpha = \psi \pm \cos^{-1} \bigg( \dfrac{\cos \theta_2 - C}{\sqrt{A^2 + B^2} } \bigg) $

where $\psi = \text{atan2}(A, B) $

( $\text{atan2}(x, y) $ is the arctangent function with two parameters )

As a numerical example, suppose

$ \mathbf{x_1} = [1, 0, 0]^T $

$ \mathbf{x_2} = [0, 0, 1]^T $

Then from the above, we have

$ \mathbf{w_1} = [0, 0, -1] $

$ \mathbf{w_2} = [0, 1, 0]^T $

Now suppose $\theta_1 = 60^\circ$ and $\theta_2 = 60^\circ$, then for equation $(1)$ we have

$ A = - \sin 60^\circ $

$ B = 0 $

$ C = 0 $

And the values of $\alpha$ are

$ \alpha = \psi \pm \cos^{-1} \bigg( \dfrac{\cos 60^\circ - 0}{ \sin 60^\circ } \bigg) $

where $\psi = \text{atan2}( - \sin 60^\circ , 0 ) = 180^\circ $

Thus $ \alpha = 180 \pm 54.7356^\circ = 234.7356^\circ , 125.26438^\circ $

Hence the first $\mathbf{u}$ is

$ \begin{bmatrix} 0 && 0 && 1 \\ 0 && 1 && 0 \\ -1 && 0 && 0 \end{bmatrix} \begin{bmatrix} \sin 60^\circ \cos 234.7356^\circ \\ \sin 60^\circ \sin 234.7356^\circ \\ \cos 60^\circ \end{bmatrix} = \begin{bmatrix} \cos 60^\circ \\ \sin 60^\circ \sin 234.7356^\circ \\ - \sin 60^\circ \cos 234.7356 \end{bmatrix} = \begin{bmatrix} 0.5 \\ - 0.707106 \\ 0.5 \end{bmatrix} $

And the second $\mathbf{u}$ is

$ \begin{bmatrix} 0 && 0 && 1 \\ 0 && 1 && 0 \\ -1 && 0 && 0 \end{bmatrix} \begin{bmatrix} \sin 60^\circ \cos 125.26438^\circ \\ \sin 60^\circ \sin 125.26438^\circ \\ \cos 60^\circ \end{bmatrix} = \begin{bmatrix} \cos 60^\circ \\ \sin 60^\circ \sin 125.26438^\circ \\ - \sin 60^\circ \cos 125.26438 \end{bmatrix} = \begin{bmatrix} 0.5 \\ 0.707106 \\ 0.5 \end{bmatrix} $

By finding the dot product with $\mathbf{x_1}$ and $\mathbf{x_2}$, we find that both solutions make an angle of $\theta_1$ with $\mathbf{x_1}$ and $\theta_2$ with $\mathbf{x_2}$.