## 2 Resolution of the Kinematic Problem by Traditional Methods
### Inverse Kinematics Using Traditional Methods
#### 2.2.2 Inverse Kinematics of the BH3-R Hexapod's Leg by the Analytical Method  
The analytical method begins with the Forward Kinematics equation system, presented in Equation (9), that calculates the position vector of the end point, \(\vec{\mathbf{p}}\), from the configuration of all actuators of the hexapod's leg (\(q_{1}\), \(q_{2}\) and \(q_{3}\)). In this equation, \(p_{x_{0}}\) represents the projection of the vector \(\vec{\mathbf{p}}\) over the \(\mathbf{X_{0}}\) axis, \(p_{y_{0}}\) is the projection over \(\mathbf{Y_{0}}\), while \(p_{x_{0}}\) constitutes the projection over \(\mathbf{Z_{0}}\):  
\[ \begin{bmatrix}p_{x_{0}}\\ p_{y_{0}}\\ p_{z_{0}}\\ 1\end{bmatrix} = \begin{bmatrix}0\\ 0\\ 1\end{bmatrix} = \begin{bmatrix}\cos(q_{1})\left[L_{1}+L_{2}\cos(q_{2})+L_{3}\sin( q_{2}-q_{3})\right]\\ \sin(q_{1})\left[L_{1}+L_{2}\cos(q_{2})+L_{3}\sin(q_{2}-q_{3})\right]\\ L_{2}\sin(q_{2})-L_{3}\cos(q_{2}-q_{3})\\ 1\end{bmatrix}  \tag{9}\]  
The solution for the first actuator of the robot, \(q_{1}\), can be obtained by dividing the second equation of the system shown in Equation (9) by the first one, as presented in Equation (10):  
\[\frac{p_{y_{0}}}{p_{x_{0}}}=\frac{\sin(q_{1})\left[L_{1}+L_{2}\cos(q_{2})+L_{3 }\sin(q_{2}-q_{3})\right]}{\cos(q_{1})\left[L_{1}+L_{2}\cos(q_{2})+L_{3}\sin(q_ {2}-q_{3})\right]}=\frac{\sin(q_{1})}{\cos(q_{1})}\implies q_{1}^{F}=\arctan \biggl{(}\frac{p_{y_{0}}}{p_{x_{0}}}\biggr{)} \tag{10}\]  
The right hand of Equation (10) shows one of the possible solutions for \(q_{1}\), the one normally labelled as \"FRONT\" (\(F\)) for this type of mechanical structure. The second possible solution is the one presented in Equation (11), which also solves Equation (10). This second solution is usually identified as \"BACK\" (\(B\)):  
\[\frac{\sin(q_{1})}{\cos(q_{1})}=\frac{p_{y_{0}}}{p_{x_{0}}}=\frac{-p_{y_{0}}}{ -p_{x_{0}}}\implies q_{1}^{B}=\arctan\biggl{(}\frac{-p_{y_{0}}}{-p_{x_{0}}} \biggr{)}=q_{1}^{F}+\pi \tag{11}\]The two possible solutions for \(q_{1}\) are presented in Equation (12), where the arctan function has been substituted by the more general atan2, which is fully defined for all the range \([-\pi,\pi]\):  
\[q_{1}^{F}=\text{atan2}(p_{y_{0}},p_{x_{0}});\hskip 14.226378 ptq_{1}^{B}=q_{1}^{F}+\pi; \tag{12}\]  
To obtain the solution for \(q_{3}\), we have to return to the definition of the Forward Kinematics equation system (see Equation (9)), and do the matrix operations shown in Equation (13):  
\[ \begin{bmatrix}p_{x_{0}}\\ p_{y_{0}}\\ p_{z_{0}}\\ 1\end{bmatrix} ={}^{0}A_{3}\cdot \begin{bmatrix}0\\ 0\\ 1\end{bmatrix} ={}^{0}A_{1}(q_{1}^{i})\cdot{}^{1}A_{2}\cdot{}^{2}A_{3}\cdot \begin{bmatrix}0\\ 0\\ 0\\ 1\end{bmatrix}  \tag{13}\] \[\Downarrow\] \[ \begin{pmatrix}{}^{0}A_{1}(q_{1}^{i})\end{pmatrix} ^{-1}\cdot \begin{bmatrix}p_{y_{0}}\\ p_{y_{0}}\\ p_{z_{0}}\\ 1\end{bmatrix} = \begin{pmatrix}{}^{0}A_{1}(q_{1}^{i})\end{pmatrix} ^{-1}\cdot{}^{ 0}A_{1}(q_{1}^{i})\cdot{}^{1}A_{2}\cdot{}^{2}A_{3}\cdot \begin{bmatrix}0\\ 0\\ 0\\ 1\end{bmatrix} ={}^{1}A_{3}\cdot \begin{bmatrix}0\\ 0\\ 0\\ 1\end{bmatrix} \] \[\Downarrow\] \[ \begin{bmatrix}p_{x_{1}^{i}}\\ p_{y_{1}^{i}}\\ p_{z_{1}^{i}}\\ 1\end{bmatrix} = \begin{bmatrix}L_{2}\cos(q_{2})+L_{3}\sin(q_{2}-q_{3})\\ L_{2}\sin(q_{2})-L_{3}\cos(q_{2}-q_{3})\\ 0\\ 1\end{bmatrix} \]  
The superscript \(i\) that appears in some terms of Equation (13) may be either \(F\) (\"FRONT\") or \(B\) (\"BACK\"), depending on the related configuration of \(q_{1}\). The terms \(p_{x_{1}^{i}}\), \(p_{y_{1}^{i}}\), and \(p_{z_{1}^{i}}\) represent the projection of the position vector over the \(\mathbf{X_{1}}\), \(\mathbf{Y_{1}}\), and \(\mathbf{Z_{1}}\) axes, respectively, taking into account that these axes depend on the aforementioned configuration of \(q_{1}\). From Equation (13), we can add the square of the first two equations of that equation system, obtaining the solution shown in Equation (14):  
\[