Inverse kinematics12 DOF

How the legs find their angles

Three joints per leg, twelve in all. Drag a target and watch the real CAD model follow.

1One leg, three joints

Three joints per leg: hip yaw, femur, knee. Angles to foot is forward; foot to angles is inverse, which is what a walking robot needs.

Loading 3D model…

Inverse · move the foot, the angles follow

2Why there are two solutions

The knee sits where two circles cross, so there are two solutions: knee up (the robot's choice) or knee down. No crossing means the foot is out of reach.

Solution used
Loading 3D model…

The real CAD leg, side-on, follows the same target.

3Reach and limits

A foot can only land in a ring around the femur pivot: at most cm out, at least cm in. Joint limits trim it further.

Loading 3D model…

Top: joint angles by distance. Bottom: degrees per mm of foot travel (capped at ), which spikes at both edges.

4The maths

Forward chain and inverse formulas (for the curious)

Forward: write the leg as a chain of matrices

Each joint is a rotation and each link a translation. Multiply them in order, from the hip down to the foot:

cos, sin depend on a joint anglebracket_offset, hip_drop, femur_length, tibia_length are fixed link sizes

Hip yaw
rotation about z
[cos⁡θ1−sin⁡θ100sin⁡θ1cos⁡θ10000100001]
Bracket
translation: out and down to the femur pivot
[100bracket_offset0100001−hip_drop0001]
Femur joint
rotation about y
[cos⁡θ20−sin⁡θ200100sin⁡θ20cos⁡θ200001]
Femur link
translation along the femur
[100femur_length010000100001]
Knee joint
rotation about y
[cos⁡θ30−sin⁡θ300100sin⁡θ30cos⁡θ300001]
Tibia link
translation along the tibia
[100tibia_length010000100001]

The last column of that product is the foot position, in terms of the joint angles.

Show the foot-position equations (last column of the product)
x=cos⁡θ1⋅R
y=sin⁡θ1⋅R
z=−hip_drop+femur_lengthsin⁡θ2+tibia_lengthsin⁡(θ2+θ3)
where R=bracket_offset+femur_lengthcos⁡θ2+tibia_lengthcos⁡(θ2+θ3) is the distance of the foot from the hip axis.

Inverse: the angles from the foot position

Solving for the angles gives the robot’s formulas:

θ1=atan2⁡(y,x)
θ2=−φ+atan2⁡(D,±A2+B2−D2)
θ3=atan2⁡(z+hip_drop−femur_lengthsin⁡θ2,R−bracket_offset−femur_lengthcos⁡θ2)−θ2
with R=x2+y2, A=−(z+hip_drop), B=bracket_offset−R, φ=atan2⁡(B,A), and
D=2⋅bracket_offset⋅R+tibia_length2−femur_length2−bracket_offset2−(z+hip_drop)2−R22⋅femur_length
Show the algebra
R−bracket_offset−femur_lengthcos⁡θ2=tibia_lengthcos⁡(θ2+θ3)
z+hip_drop−femur_lengthsin⁡θ2=tibia_lengthsin⁡(θ2+θ3)
Move the femur terms across. Square both lines and add: cos² + sin² = 1 removes θ₃.
(R−bracket_offset−femur_lengthcos⁡θ2)2+(z+hip_drop−femur_lengthsin⁡θ2)2=tibia_length2
Multiply out and collect the sine and cosine of θ₂: Asin⁡θ2+Bcos⁡θ2=D

± is knee up or knee down. If A² + B² − D² is negative, the foot is out of reach.

Background: Modern Robotics.