3 joint Geometric-based Inverse kinematics

I have managed to make inverse kinematics for 2 joints, but I also want to make inverse kinematics
for 3 joints, with the purpose of mainly procedurally animating robots.
The problem I am facing is that any tutorials I find fail to explain what everything does which makes it hard if not impossible for me to implement.

Basically what I would like to achieve would look something like this:
image
The neon ball is the origin of the leg, and the foot is the target.

Any help such as directions to useful resources or already made Geometric-based 3 joint inverse kinematics that I could learn from will be appreciated!

I figured it out after looking through a book about math, will post how soon.

Interesting, what is the method called?

Otherwise I can suggest my CCD and my module on it but it is an iterative method which doesnt always generate the same end result depending on the initial conditions.

1 Like

Ok so I took a picture of the book and translated everything I could with extra notes.


While this does in fact work like the example above that I wanted to achieve stuff likes mechs that you had in your posts wont work with this, as this mainly only works for stuff like spiders. and other insects

and another note, once you get the angle in radiants you still have to substract the angle from math.pi (or 180 degrees in radiants)

function IKSolver.Solve3Joint(originCF: CFrame, targetPos: Vector3, l1: number, l2: number, l3: number): (CFrame, number, number)
	local localized = originCF:PointToObjectSpace(targetPos)
	local l4 = localized.Magnitude
	
	
	local planeCF = originCF * CFrame.fromAxisAngle(
		(Vector3.zAxis * -1):Cross(localized.Unit), -- Axis
		math.acos(-localized.Unit.Z) -- Angle
	)

	local ed = l4 - l2
	
	local a4 = math.acos((ed^2 + l3^2 - l1^2)/(2*ed*l3))
	
	local a1 = math.acos((l1^2 + ed^2 - l3^2)/(2*l1*ed))
	local a2 = math.pi - a1
	local a3 = math.pi - a4
	
	a1 = math.pi - a1
	a2 = math.pi - a2
	a3 = math.pi - a3

	return planeCF * CFrame.Angles(math.rad(-90),0,0), a1, a2, a3
end

here would be the entire code for the arm (I removed some other stuff such as a part of code that makes sure that the hand fully reaches the target instead of pointing at it)

Origin.Weld.C0 = Origin.CFrame:ToObjectSpace(planeCF) * CFrame.Angles(upperAngle, 0, 0)
UpperPart.Weld.C0 = MiddleC0Cache * CFrame.Angles(middleAngle, 0, 0)
MiddlePart.Weld.C0 = LowerC0Cache * CFrame.Angles(lowerAngle, 0, 0)

And this is how to use it with a rig, but please not that it wasn’t tested with motor6D but instead uses welds.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.