The FABRIK (Forward And Backward Reaching Inverse Kinematics) algorithm is used in computer graphics and robotics to solve the inverse kinematics problem efficiently. Inverse kinematics is about figuring out the joint angles of a robotic arm or the position of a character's limbs given a desired end-effector position (like the hand of a robot or the foot of a character in animation).
- Define the initial configuration of joints in the chain (e.g., segments of a robotic arm or bones of a character's limb).
- Specify the target position for the end effector.
it should look something similar to this where there is the limb, a start position and an end effector
We will start with the Backwards reaching phase:
- Set the current end position of the limb, denoted as P3, to the end effector position.
- Iterate through the chain from end to start: (in this situation P3 is the current point being worked on while P2 is the point before it)
- Compute the direction from the new P3 to the previous joint P2.
- Move the segment (from P3 to P2) to align with this direction.
- This may result in P0 (the root joint) being offset from the limb's root, we fix that in the next method
we should get something like this
- Reset P0 to the limb's root position.
- Iterate through the chain from start to end:
- Compute the direction from the new P0 to the next joint.
- Move the segment (from P0 to the next joint) to align with this direction.
Repeat these two methods until the end effector reaches a specific distance from the target position, or until both P3 and the end effector are within a tolerance level.
- If the end effector is out of reach, the limb will fully extend naturally.
- Check if the total length of the limb (sum of segment lengths) is less than the distance between the limb's root and the end effector. If so, the end effector is out of reach.
- Initially extend the limb fully towards the desired point.
- Iterate through the FABRIK algorithm (backwards and forwards reaching phases) for at least 10 iterations. (10 as a "maximum" is not required, just recommended for most use cases)
The limb bends towards the desired point while ensuring that P3 (the end effector) remains at the target