HomeArticlesRobotics & Kinematics

Hexapod Walker Gait Planning: Inverse Kinematics and the Tripod Gait

Six legs, each solving the same law-of-cosines geometry problem every frame, coordinated into a tripod gait that never leaves the robot balanced on fewer than three feet.

mysimulator teamUpdated June 2026≈ 8 min read▶ Open the simulation

Six legs, one geometry problem repeated six times

A hexapod's legs are controlled independently, but each one solves the identical small geometry problem: given a target foot position, what shoulder and knee angles put the foot exactly there? This is inverse kinematics (IK), and for a two-link leg (femur length L1, tibia length L2) it has a closed-form, no-iteration solution using nothing more than the law of cosines.

live demo · six legs cycling through a tripod gait● LIVE

Analytical two-link IK

d = distance from hip to target foot position
θ2 = acos( (d² − L1² − L2²) / (−2·L1·L2) )     ← knee angle, law of cosines
θ1 = atan2(target_y, target_x) − acos( (L1² + d² − L2²) / (2·L1·d) )   ← hip angle

reachable only if |L1 − L2| ≤ d ≤ L1 + L2, otherwise the target is out of range

Because this is a closed-form formula rather than an iterative numerical solver, each of the six legs computes its joint angles in a fixed, tiny number of trigonometric operations, cheap enough to run every frame for every leg with room to spare — important for a hexapod, since each leg needs a fresh IK solve as its target foot position moves through the gait cycle. The only real complication is the acos argument occasionally falling outside [−1, 1] due to an unreachable target, which the simulation clamps rather than letting produce NaN angles.

The tripod gait: three legs down, three legs swinging, always

A hexapod's core stability advantage over two- or four-legged robots is that it can always keep a stable tripod of feet on the ground while the other three swing forward. Standard leg numbering splits the six legs into two alternating groups, {R1, L2, R3} and {L1, R2, L3} (front-right, middle-left, rear-right versus front-left, middle-right, rear-left), and the tripod gait simply swaps which group is grounded and which is swinging every half-cycle. Three points define a plane, so three feet on the ground at any triangle wider than the body's footprint keeps the centre of mass within the support polygon at every instant — the robot is statically stable throughout the entire gait, never balancing on fewer than three points.

Wave gait: slower, but stable on rougher ground

The wave gait trades speed for an even wider margin of stability: only one leg lifts and swings at a time, so five feet are always on the ground. This raises the support polygon's margin substantially, at the cost of needing six sequential phases to advance all six legs instead of the tripod gait's two, roughly a third of the top speed. On the bumpy terrain setting in this simulation, the wave gait's larger support base and lower per-step disturbance make it noticeably more robust to uneven footing, which is exactly the trade real legged robots make when moving from flat factory floors to rubble or loose ground.

Why legs beat wheels on broken ground

A wheel needs a continuous path of support under it at every point along its rotation; a leg only needs discrete footholds, and it can place each foothold individually by solving IK for wherever solid ground actually is, stepping clean over gaps a wheel would fall into. That flexibility is exactly why legged locomotion, at real mechanical and control cost, remains the standard approach for robots meant to operate on stairs, rubble or genuinely unstructured terrain rather than flat floors.

Frequently asked questions

Why does a hexapod use six legs instead of four or two?

Six legs let the robot always keep a stable tripod (or more) of feet on the ground while the rest are swinging, so it never needs active balance control the way a biped does. Four- and two-legged robots can walk but generally need dynamic balancing during part of their gait cycle; six legs make static stability achievable throughout.

What does it mean for the inverse kinematics to be 'analytical'?

It means the joint angles are computed directly from a closed-form trigonometric formula (the law of cosines here), rather than searching iteratively toward a solution the way numerical IK solvers do for more complex arm geometries. For a simple two-link leg this direct formula is exact, instantaneous and cheap enough to solve fresh every frame for all six legs.

When would you use the wave gait instead of the faster tripod gait?

On rough or uncertain terrain, where keeping five feet on the ground at all times (instead of three) gives a much larger margin against a single foot losing traction or finding no solid footing. The tripod gait is faster but leaves the robot balanced on the minimum three points, which is riskier when the ground itself is unreliable.

Try it live

Everything above runs in your browser — open Hexapod Walker and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.

▶ Open Hexapod Walker simulation

What did you find?

Add reproduction steps (optional)