I have a machine that rotates two concentric frames. The outer frame has a motor that rotates it relative to the global y-axis, and the inner frame has a motor that rotates it about the outer frame's z-axis as pictured below. How can I find the angle of rotation for each motor given the inner frame's normal vector? I need to rotate both frames so the inner frame can be oriented in a given direction.

Similar machine to what I am working on

(This isn't my machine but it provides a clear image of what I am working with)

(I know how to get from the motors' angles to the direction in which they are pointing, but when I solve the equation for the motors' angles they give me incorrect values)

  • $\begingroup$ What is the form that you have the direction? Is it a vector triplet or some other form? $\endgroup$
    – NMech
    Aug 6, 2021 at 18:59
  • 1
    $\begingroup$ Please add the formula for the calculation to go from motor angle to direction vector. It is most likely to be invertible. You may have inverted the equations incorrectly. Please also add descriptions of the variables used along with a neat figure so that the axis, angle and sign conventions are clear. $\endgroup$
    – AJN
    Aug 7, 2021 at 1:13
  • $\begingroup$ Invertible almost every where. You can run into division by zero error at certain vector directions (usually near 90deg) this problem is very similar to radar antenna pointing problem. Two angles, one radar pointing direction. $\endgroup$
    – AJN
    Aug 7, 2021 at 1:16
  • 1
    $\begingroup$ Ideally, you should how you get from the motors' angles to the direction in which they are pointing, so that answers have a starting point. It is also customary to reference the web graphics you use. $\endgroup$ Aug 8, 2021 at 19:40

4 Answers 4


If we set the outer frame at 90 degrees to XY plane, parallel to Z as reference. then let's call the angle of inner-frame measured counterclockwise from the Y-axis, $\omega$ and our spherical coordinate angles $\alpha \quad and \quad \theta$ as standard notation.

Then if we consider the intersection of a cone with the angle $2\omega$ and our coordinate sphere with the radius $r=1 \ $ we have a circle in a plane parallel to Z plane with the radius $r= arcsin (\omega)$ and this property

$$sin^2 \alpha +sin^2 (\pi/2 - \theta) = sin^2 \omega$$

So we have to set the inner-frame at $\omega$ from Y-axis while holding the outer frame parallel to Z-axis then turn the outer frame by angle $=arcsin(\alpha)$

A figure will clarify this and after my dirt biking trip, I will draw it.


I must admit I am not sure which are your coordinate axles and rotation directions, but the normal vector should be easy to say in properly selected coordinates:

enter image description here

Only the moving frames are drawn. The bigger of them rotates around axis C in my rectangular ABC coordinate system. In the image it is angle e off from the zero position (= AC plane) The inner frame is angle d off from its zero position.

Actually angles d and e alone define the direction of the wanted normal vector (=green). It points angle e upwards from horizontal plane AB and angle e to counterclockwise from axis A when watched downwards.

If we have unit vectors (length=1) Ao, Bo and Co to the directions of the coordinate axles A, B and C we can say formally the unit vector which points to the wanted normal direction:

sin(e)cos(d)Ao + cos(e)cos(d)Bo + sin(d)Co

I guess it may be useful to set the absolute coordinate origin to the midpoint of the rotating planes because it doesn't move. All formulas which contain places will be a little shorter (=no offset). It doesn't affect to the presented equations.

Reversing: angle d occurs as only angle in the C-component (=sin(d)) of the normal unit vector. You get 2 possible d-values. Which of them to use depends on other requirements, for ex. shortest movement or less waste of energy or time due braking and accelerating. It can be useful to explore also the caused possible rotations around the other axis and make the decision after it.

You have selected the d, then you have also cos(d) and you can calculate components sin(e) and cos(e) from the known values of cos(d)sin(e) and cos(d)cos(e).

There are 2 values for e for the wanted sin(e) and 2 values of e for the wanted cos(e). You must check which e is common for the known sin(e) and known cos(e).

If cos(d) happens to be =0 i.e. upwards or downwards in my image, any e will do.

Not asked: If you plan a kind of motion tracking system you are jumping in the area of robot and weapon technologies. To make a reliably working control system you need math which is in totally different sophistication level than my elementary calculations. University level control theory contains it.


If you have a normal vector $\begin{bmatrix}\hat{x_0}\\\hat{y_0}\\\hat{z_0}\end{bmatrix}$ with $z$ in direction of the first motor, then de angle of that motor should be the angle of the vector over the tangent plane, so $\theta=arctan(\frac{\hat{y_0}}{\hat{x_0}})$, the internal relative motor would depend only in $z$, $\phi=arcsin(\hat{z_0})$.


Another way to solve this is through rotation matrices (or homogeneous matrices). (this actually is a very basic problem in inverse kinematics of robotics).

The rotation matrices about axis Y and Z by an angle $\theta$ are given by

$$R_y(\theta) = \begin{bmatrix}\cos\theta & 0 & -sin\theta \\0& 1&0 \\sin\theta & 0& \cos\theta \end{bmatrix} \qquad R_z(\theta) = \begin{bmatrix}\cos\theta & -sin\theta & 0\\ sin\theta& \cos\theta& 0 \\0& 0&1\end{bmatrix} $$

assuming that

  • axis z is the horizontal one (aligns with the bearing of the larger frame) and
  • axis y is the vertical (aligns with the bearing of the inside frame when the larger and smaller frames are aligned and vertical - hopefully the following depiction will explain what I mean )

enter image description here

Figure : Global X,Y,Z axis (in perspective). The position of the machine is arbitrary (the alignment of X axis is only by chance!)

Please note that:

  • GLOBAL Z-axis is aligned with the outer frame bearings,
  • GLOBAL Y axis is vertical, and
  • GLOBAL X is perpendicular to the other two ( I just noticed that the direction should be opposite to obey the right hand rule, but I won't bother making another )

Then the overall rotation matrix, for the outside frame rotating by $\theta$, and the inside rotating by $\phi$ then its:

$$R_y(\phi) R_z(\theta) = \begin{bmatrix}\cos\theta & 0 & sin\phi\\0& 1&0 \\ -sin\phi & 0& \cos\phi \end{bmatrix} \begin{bmatrix}\cos\theta & -sin\theta & 0\\ sin\theta& \cos\theta& 0 \\0& 0&1\end{bmatrix} $$


$$R_y(\phi) R_z(\theta) = \begin{bmatrix} \cos\left(\phi \right)\,\cos\left(\theta \right) & -\sin\left(\theta \right) & \cos\left(\theta \right)\,\sin\left(\phi \right)\\ \cos\left(\phi \right)\,\sin\left(\theta \right) & \cos\left(\theta \right) & \sin\left(\phi \right)\,\sin\left(\theta \right)\\ -\sin\left(\phi \right) & 0 & \cos\left(\phi \right) \end{bmatrix}$$

The way you'd use this, assuming that the initial position normal (inside and outside aligned and vertical) is $e_{n,0}= \begin{bmatrix} 1\\ 0\\ 0\end{bmatrix}$, is that you'd multiply:

$$R_y(\phi) R_z(\theta) e_{n,0} = \begin{bmatrix} \cos\left(\phi \right)\,\cos\left(\theta \right)\\ \cos\left(\phi \right)\,\sin\left(\theta \right)\\ -\sin\left(\phi \right) \end{bmatrix}$$

Now assuming for example that the new normal is $e_{n,1} = \begin{bmatrix} 0\\ 1\\ 0\end{bmatrix}$

then simply have: $$\begin{bmatrix} \cos\left(\phi \right)\,\cos\left(\theta \right)\\ \cos\left(\phi \right)\,\sin\left(\theta \right)\\ -\sin\left(\phi \right) \end{bmatrix} = \begin{bmatrix} 0\\ 1\\ 0\end{bmatrix}$$

or (equally) the following three equations:

$$ \begin{cases} \cos(\phi )\,\cos(\theta ) =0\\ \cos(\phi )\,\sin(\theta )=1\\ -\sin(\phi )=0 \end{cases}$$

NOTE: this condition applies to any normal so you don't need to recalculate the above. You only need to solve the above system.

To solve the system:

$$ \begin{cases} \cos(\phi )\,\cos(\theta ) =0\\ \cos(\phi )\,\sin(\theta )=1\\ -\sin(\phi )=0 \end{cases} \rightarrow \begin{cases} \cos(\phi )\,\cos(\theta ) =0\\ \cos(\phi )\,\sin(\theta )=1\\ \color{red}{\phi= 0 \text{ or } \phi= \pi} \end{cases} \rightarrow \begin{cases} \text{if } \phi= 0 \begin{cases} \color{red}{1}\,\cos(\theta ) =0\\ \color{red}{1}\,\sin(\theta )=1 \end{cases}\\ \text{if } \phi= \pi \begin{cases} \color{red}{-1}\,\cos(\theta ) =0\\ \color{red}{-1}\,\sin(\theta )=1 \end{cases} \end{cases} \rightarrow \begin{cases} \text{if } \phi= 0 \color{red}{\text{ then } \theta=\frac{\pi}{2}} \\ \text{if } \phi= \pi \color{red}{\text{ then } \theta=-\frac{\pi}{2}} \end{cases} $$

This is an example that shows that you can achieve the same position with two different angle configurations.

  • $\begingroup$ axis z is the horizontal one (aligns with the bearing of the larger frame - Easily seen from drawing. But does y-axis align with bearing of second frame. As you have drawn it x is aligning with that bearing. $\endgroup$ Aug 9, 2021 at 17:30
  • $\begingroup$ I assume that the storage/ nitial position is with both frames planes aligned with the yz plane. $\endgroup$
    – NMech
    Aug 9, 2021 at 17:31
  • $\begingroup$ So vertical. The math is the math, but it disagrees with the drawing. $\endgroup$ Aug 9, 2021 at 17:34
  • $\begingroup$ @StainlessSteelRat, I am not sure I follow why there is disagreement. I (re)used the drawing to draw the global XYZ for the machine. The current frame will change. When the frames are aligned vertical (which I assume the position where $\phi=0$ and $\theta=0$ , then the Z axis will align with the outer frame bearings, and Y will align with the inner frame bearings. The position of the machine is an arbitrary position. I just notice why there might be a confusion in the drawing, but the X axis is just perpendicular to Y and Z (which passes through the bearings of the external) $\endgroup$
    – NMech
    Aug 9, 2021 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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