Getting angles for rotating $3$D vector to point in direction of another $3$D vector

1.4k Views Asked by At

I've been trying to solve this in Mathematica for $2$ hours, but got the wrong result.

I have a vector, in my case $\{0, 0, -1\}$. I want a function that, given a different vector, gives me angles DX and DY, so if I rotate the original vector by an angle of DX around the X axis, and then rotate it by an angle of DY around the Y axis, I'll get a vector with the same direction as the given vector.

(I want this so I could input angles to SolidWorks to rotate a part so it will satisfy a constraint I defined in Mathematica.)

2

There are 2 best solutions below

4
On BEST ANSWER

So you need a 3×3 rotation matrix $E$ such that

$$ E\,\begin{pmatrix} x \\ y \\ z \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \\ -1 \end{pmatrix} = -\hat{k} $$

This rotation matrix consists of two elementary rotations

$$ \begin{aligned} E & = {\rm Rot}(\hat{i},\varphi_x){\rm Rot}(\hat{j},\varphi_y) \\ & = \begin{pmatrix} 1 & 0 & 0 \\ 0 & \cos\varphi_x & -\sin\varphi_x \\ 0 & \sin\varphi_x & \cos\varphi_x \end{pmatrix} \begin{pmatrix} \cos\varphi_y &0 & \sin\varphi_y \\ 0 & 1 & 0 \\ - \sin\varphi_y & 0 & \cos\varphi_y \end{pmatrix} \end{aligned} $$

This is solved with

$$ \varphi_x = - \tan^{-1} \left( \frac{y}{\sqrt{x^2+z^2}} \right) \\ \varphi_y = \pi - \tan^{-1} \left( \frac{x}{z} \right) $$

if $\sqrt{x^2+y^2+z^2}=1$ is true.

Verification

use $(x,y,z) = (\frac{1}{2}, \frac{3}{4}, \frac{\sqrt{3}}{4}) = (0.5, 0.75, 0.4330) $ to get

$$ \varphi_x = - \tan^{-1} \left( \frac{\frac{3}{4}}{\sqrt{\left(\frac{1}{2}\right)^2+\left(\frac{\sqrt{3}}{4}\right)^2}} \right) = -0.8481 \\ \varphi_y = \pi - \tan^{-1} \left( \frac{\frac{1}{2}}{\frac{\sqrt{3}}{4}} \right) = 2.2845$$

With a rotation matrix

$$ E = \begin{pmatrix} -0.6547 & 0 & 0.7559 \\ -0.5669 & 0.6614 & -0.4910 \\ -0.5 & -0.75 & -0.4330 \end{pmatrix} $$

and $$ \begin{pmatrix} -0.6547 & 0 & 0.7559 \\ -0.5669 & 0.6614 & -0.4910 \\ -0.5 & -0.75 & -0.4330 \end{pmatrix} \begin{pmatrix} 0.5 \\ 0.75 \\ 0.4330 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \\ -1\end{pmatrix} $$


NOTICE: Some combinations of $(x,y,z)$ will not yield the correct result because it won't be possible with the specific rotation sequence used.

0
On

Okay, if you don't mind rotating about the y and z axes, we can do it like this. Let's take a typical vector like (6,3,2) so the overall length is 7. You want to rotate a vector from the z axis into this orientation. First you look at the angle whose cosine is 2/7...that's how far down you have to come from the z axis. So you rotate about the y axis by that amount. Now you just have to swing around the z axis by the angle whose tangent is 3/6.

I think that's all you need to line up your vectors.enter image description here