Inspiration

The following video from YouTube struck me as a good use case for FoldPairList.

Functions

The function fabrikStep performs the translation & rotation on one single leg in the jointed structure. It requires the vector we want transformed and the target point where we want the transformed vector to be rooted. This function will be called by fabrik.
In[]:=
fabrikStep[newroot:{_,_},vector:{r:{_,_},t:{_,_}}]:=​​With[​​{len=Norm[t-r]},​​{new={newroot,newroot+len Normalize[r-newroot]}},​​{new,Last[new]}]
The function fabrik implements the forward-backward algorithm. To make this a complete implementation, we’d need to add a tolerance and repeat the forward-backward algorithm until the desired tolerance is achieved.
In[]:=
fabrik[path:{{_,_}...},target:{_,_}]:=​​With[​​{vecs=Partition[path,2,1]},​​{pass1=FoldPairList[fabrikStep,target,Reverse@vecs]},​​Prepend[FoldPairList[fabrikStep,First@path,Reverse@pass1][[All,2]],path[[1]]]​​]

Demonstration

Trying a few different random starting paths shows multiple passes through the algorithm may be necessary.
With​​{testPath=AnglePath[Table[{RandomReal[{.5,1.5}],RandomReal[{-Pi/2,Pi/2}]},{4}]],​​target={.5,.5}},​​{pass1=fabrik[testPath,target]},​​{pass2=fabrik[pass1,target]},​​Graphics​​Green,AbsolutePointSize[10],Point[testPath[[1]]],​​Red,AbsolutePointSize[10],Point[target],​​Blue,Arrow[testPath],​​
,Axes->True
Out[]=
We can watch the segmented structure deform as we pull the endpoint dynamically.
In[]:=
DynamicModule[​​{path=AnglePath[Table[{RandomReal[{3,10}],RandomReal[{-Pi/2,Pi/2}]},{5}]]},​​Manipulate[Graphics[{Blue,Arrow[path=fabrik[path,p]]},PlotRange->30],{{p,Last@path},Locator}],SaveDefinitions->True]
Out[]=
​

CITE THIS NOTEBOOK

Implementing FABRIK with Wolfram: forward and backward reaching inverse kinematics​
by Eric Rimbey​
Wolfram Community, STAFF PICKS, February 23, 2026
​https://community.wolfram.com/groups/-/m/t/3644173