Trying to solve a pair of trigonometric simultaneous equations I have a machine that has two shafts which are the inputs and their position is set by 2 servo motors.
Depending on the angle of these two shafts (shaft 1 has an angle designated $Ta$ degrees, shaft 2 has an angle designated $Ba$ degrees) a set of gimbals rotates and tilts an attached plate, which is the output of the machine. ( A mirror for reflecting a light beam.)
I have worked out that the plate position designated by the two angles $Pa$ and $Pb$ are related by the following two equations:
$Cos(Pa) = Cos(Ta) * Cos(Ba)$
$Tan(Pb) = {sin(Ta) \over Tan(Ba)}$
$Tb$ has a range of $0$ to $180$ degrees
$Ta$ has a range of $0.001$ to $90$ degrees
Using these 2 equations I can work out the position of the plate given $Ta$ and $TB$
What I would like to do is solve the 2 equations so I can specify $Pa$ and $Pb$ (the required plate location) and calculate $Ta$ and $Ba$ so I can then set the angle of my 2 input shafts accordingly.
Any help would be greatly appreciated As I am no mathematician and struggling with this.
 A: Okay, you have the system
$$\cos(T_a) \cos(B_a) = \cos(P_a)$$
$$\sin(T_a) \cot(B_a) = \tan(P_b)$$
Since $P_a$ and $P_b$ are given, let's just give names to the values on the right-hand sides:
$$\cos(T_a) \cos(B_a) = C$$
$$\sin(T_a) \cot(B_a) = D$$
We can solve for $\sin(T_a)$ and $\cos(T_a)$:
$$\cos(T_a) = C \sec(B_a)$$
$$\sin(T_a) = D \tan(B_a)$$
Now let's use the Pythagorean theorem:
$$1 = \sin^2(T_a) + \cos^2(T_a) = C^2 \sec^2(B_a) + D^2 \tan^2(B_a)$$
Now we've got an equation just involving $B_a$.  Let's multiply through by $\cos^2(B_a)$ so that we've got everything in terms of sines and cosines:
$$\cos^2(B_a) = C^2 + D^2 \sin^2(B_a)$$
Use the Pythagorean theorem again to get everything in terms of cosines:
$$\cos^2(B_a) = C^2 + D^2(1- \cos^2(B_a))$$
Solving,
$$\cos(B_a) = \pm \sqrt{\frac{C^2+D^2}{1+D^2}}$$
Now remember from the beginning that
$$\cos(T_a) \cos(B_a) = C$$
so we have
$$\cos(T_a) = C/\cos(B_a) = \pm C \sqrt{\frac{1+D^2}{C^2+D^2}}$$
Replacing $C$ and $D$, we get
$$\cos(B_a) = \pm \sqrt{\frac{\cos^2(P_a) + \tan^2(P_b)}{1 + \tan^2(P_b)}}$$
$$\cos(T_a) = \pm \cos(P_a) \sqrt{\frac{1 + \tan^2(P_b)}{\cos^2(P_a) + \tan^2(P_b)}}$$
Notice that, by the Pythagorean theorem, we have
$$1 + \tan^2(P_b) = \sec^2(P_b)$$
So we can rewrite this as
$$\cos(B_a) = \pm \cos(P_b) \sqrt{\cos^2(P_a) + \tan^2(P_b)}$$
$$\cos(T_a) = \pm \frac{\cos(P_a)}{\cos(P_b)} \cdot \frac{1}{\sqrt{\cos^2(P_a) + \tan^2(P_b)}}$$
(Hopefully I didn't make any mistakes, but I haven't exactly run over it with a fine-toothed comb.  That said, this general method will solve the problem even if I dropped a sign or something somewhere.)
That gives you (generically) eight different solutions for $B_a$ and $T_a$ for fixed $P_a$ and $P_b$ -- you can choose plus or minus, and then you have two choices for each inverse cosine.  I'm assuming you won't have any trouble picking the one that's geometrically meaningful for your application.
A: I'll simplify your notation a bit, using shaft angles $T$ and $B$ (rather than $T_a$ and $B_a$), and plate angles $P$ and $Q$ (rather than $P_a$ and $P_b$). The given equations are
$$\cos P = \cos T \cos B \qquad\qquad
\tan Q = \frac{\sin T}{\tan B} \tag{$\star$}$$
Solving these for $\cos T$ and $\sin T$, we eliminate $T$ via the relation $\cos^2 T + \sin^2 T = 1$:
$$\begin{align}
\left(\frac{\cos P}{\cos B}\right)^2 + \left(\tan Q \tan B\right)^2 = 1 &\quad\to\quad \frac{\cos^2 P}{\cos^2 B} + \frac{\tan^2 Q \sin^2 B}{\cos^2 B} = 1 \\[6pt]
&\quad\to\quad \cos^2 P + \tan^2 Q \sin^2 B = \cos^2 B \\
&\quad\to\quad \cos^2 P + \tan^2 Q (1-\cos^2 B) = \cos^2 B \\
&\quad\to\quad \cos^2 P + \tan^2 Q = \cos^2 B ( 1 + \tan^2 Q) = \frac{\cos^2 B}{ \cos^2 Q }
\end{align}$$
Therefore,
$$\begin{align}
\cos^2 B &= \cos^2 Q \left( \cos^2 P + \tan^2 Q \right) = \cos^2 P \cos^2 Q + \sin^2 Q \\
&= ( 1 - \sin^2 P)\cos^2 Q + \sin^2 Q = \cos^2 Q + \sin^2 Q - \sin^2 P \cos^2 Q \\
&= 1 - \sin^2 P \cos^2 Q \\[6pt]
\sin^2 B &= \sin^2 P \cos^2 Q
\end{align}$$ 
and we can write

$$ \cos B = \pm \sqrt{ 1 - \sin^2 P \cos^2 Q } \qquad\qquad \sin B = |\sin P \cos Q|$$

where the "$\pm$" depends $B$'s quadrant, and the "$|\cdot|$" ensures that that quadrant is I or II. Substituting these into $(\star)$, we can solve for functions of $T$:

$$\begin{align}
\cos T &= \frac{\cos P}{\cos B} = \frac{|\cos P|}{\sqrt{1-\sin^2 P \cos^2 Q}} \\[6pt]
\sin T &= \tan B \tan Q =\frac{|\sin P \cos Q \tan Q|}{\sqrt{1-\sin^2 P \cos^2 Q}} = \frac{|\sin P \sin Q|}{\sqrt{1-\sin^2 P \cos^2 Q}} \\[6pt] \tan T &= \left|\frac{\sin P \sin Q}{ \cos P}\right| = \left| \tan P \sin Q \right|\end{align}$$

where the "$\pm$"s vanish but "$|\cdot|$"s remain, to ensure that $T$ is a first-quadrant angle. In fact, when $\cos T \neq 0$, the relation $\cos P = \cos T \cos B$ tells us that $\cos B$ and $\cos P$ share a sign, which resolves the "$\pm$" ambiguity for $\cos B$. (However, when $\cos T = 0$, we also have $\cos P = 0$. In this case, the "$\pm$" remains for $\cos B$, although the expression simplifies to $\cos B = \pm \sin Q$; likewise, $\sin B = |\cos Q|$.)
This agrees with @Daniel's answer, although the final expressions are perhaps a little cleaner here (and maybe also the derivation).
