Draw a circle around your origin point, whose radius isLet's attack this in parts: we'll find where to place the lengthend of yourthe first bone, then figure out where the other two go. Once we've arranged the first bone, what remains is a two-bone IK problem, which we already know how to solve analytically.
Draw a second circle around your target point, whose radiusThe trick is to understand the sum ofconstraints on where the lengthsend of your latter twothe first bone can end up. It can't be further away from the target than the remaining bones can reach, ie.
Distance(1st bone end, target) <= Length(2nd bone) + Length(3rd bone)
IfAnd it also can't be closer to the circles do not overlap (ie. D(origin, target) > L(B1) + L(B2) + L(B3) ), or than the second circle is wholly insideshortest length the first (ie. D(origin, target) + L(B2) + L(B3) < L(B1) )remaining bones can fold to, then there is no feasible solutionie.
Distance(1st bone end, target) >= Abs(Length(2nd bone) - Length(3rd bone)
If they do intersectAnd lastly, or the endpoint of the first circle is wholly insidebone can't be closer or further from the second, then choose anystart point onthan the firstbone's own length:
Distance(1st bone end, origin) = Length(1st bone)
Taking these three constraints together, we have an interesection between a circle that's inside(the sweep of the first bone) and an annulus (the allowable places the remaining bones can start and still reach the target)
Points where your second1st bone circle. This will be (red) intersects the endouter rim of your firstthe annulus (teal) correspond to solutions where the 2nd and 3rd bone are pulled into a straight line to reach their maximum extent.
What remains is now aPoints where it intersects the inner rim correspond to solutions where the remaining two-bone IK problem bones are forced to get from this first bone endpointfold 180 degrees to collapse as tightly as possible.
Any intermediate point along the target, and you're guaranteed thatarc(s) of overlap between the target is in rangecircle and annulus (though differences in arm lengths, joint angle constraints, or obstacles could still block the solutionfine solid red curves). You can apply are solutions where the normal twosecond elbow bends some intermediate amount -bone techniques to that reduced problem tighter further in, looser further out.
The trick here is whenYou can pick any point you have a wide rangelike along those curves of possible points for that first boneoverlap - each of the infinite choices corresponds to end ata feasible solution (barring obstacles / joint angle limits). SomeBut some options along these arcs might be better than others, based on considerations like...
- Differences in length between your remaining bones
- Proximity to the arm's previous pose
- Continuity with the arm's previous motion
- Balancing the amount of bending between the joints
- Prioritizing more bending at freer joints and less at stiffer/more expensive joints
...etc. What heuristics/algorithms you apply here will depend on your context and how you want the arm to behave.