I’ve been aiming to atleast start out and get into the whole IK (Inverse Kinematics) area and was recently suggested to learn from a Wiki article about FABRIK by a friend. I have been trying to understand some solving code from said article and have found myself stuck, here’s the solving code:
function chain:solve()
local distance = (self.joints[1] - self.target).magnitude;
if distance > self.totallength then
-- target is out of reach
for i = 1, self.n - 1 do
-- create direct line to target and travel join distance across it
local r = (self.target - self.joints[i]).magnitude;
local l = self.lengths[i] / r;
-- find new joint position
self.joints[i+1] = (1 - l) * self.joints[i] + l * self.target;
end;
end;
end;
Here’s what I have failed to grasp (Line 6-10):
-- create direct line to target and travel join distance across it
local r = (self.target - self.joints[i]).magnitude;
local l = self.lengths[i] / r;
-- find new joint position
self.joints[i+1] = (1 - l) * self.joints[i] + l * self.target;
I’m somewhat familiar with the whole concept of FABRIK (I watched EgoMoose’s video on FABRIK) being based on anchoring one end and constructing the whole system from that point. However, I can’t understand any math that happens in this part except the literal fact that r
gets the magnitude of the difference of the join from the the target, I’ve comprehended nothing else. I’ve tried looking at it practically and have asked around but I’m still stuck up here. I would heavily appreciate any attempts to even slightly describe what’s going on in that code or any links/concepts one might suggest to learn from.
Thank you,
Ankur_007