# Inverse Kinematics: Part 3 - Full Leg Solution

Quick progress this time! Given that the hip joint is orthogonal to the lower two joints (who's positional solution was wrapped up in the first post) it's an almost trivial step to extend the maths to cover three leg joints and a foot position in three dimensions. Complication is that this new set of leg solutions is just going to introduce another coordinate system. By the time I get to finishing up the whole of Hexy, I'm going to be knee-deep in them!
[WARNING: maths in post]

For this, we'll take a standard right-hand Cartesian coordinate system, with the leg's hip joint at the origin. The hip's axis is the z-axis and at hip=0, the knee and ankle joints are in the y-axis direction. Variables $\theta$, $\phi$, a and b are the same as previous. This time though there is also the length of the upper leg joint (h) and the angle of the hip $\alpha$. NB in terms of the lengths of the leg sections I'll plan to use these measurements for any finite calculations.

So I want to put the foot at a point in this space F where is $(F_x,F_y,F_z)$. First part of the solution is to get the hip angle. This is simple (think looking at the leg from on top):

$\large \tan \alpha = \frac{F_y}{F_x}$
$\large \alpha = \tan^{-1}\left (\frac{F_y}{F_x}\right )$

Now that we know the plane in which the lower leg joints are moving, all that we need to do is calculate the equivalents of x and y from the first post. Quick bit of geometry here and we get to:

$\large x = \sqrt{F_x^2+F_y^2}-h$
$\large y = F_z$

With all these in tow, we can now put a foot where we want. All that remains is to transform the individual leg solutions to their respective locations around the robot. With a transformation of Hexy's global coordinate system (shifts and rotations) Hexy can now fully articulate itself with a closed form set of positional equations.

At some point in the future I'll write down all these equations in a nice neat manner and put up some python code to implement it.