I am currently designing a 2D simulation of a 3DOFs robotic arm in order to develop a better understanding of inverse kinematic (so as to avoid breaking more components than necessary) but despite my numerous readings I still cannot figure out how apply it to my arm.

I tried to represent my arm joints as a combination of three circle radiuses, or using complex exponential form (I did a very simple modelization using Geogebra), but no matter the method I can't figure out how to constrain my problem.

During my research I came across this blog: Inverse kinematics of 3-link arm with constrained minimization in Python and I found the solution really elegant, but even if it feels logical, I don't understand it.

What's the math behind it? Is it based on Lagrange multiplier?

What I understand is that we want to find the appropriate combination of three angles so that the end effector of our robot ends up at the right position. I understand there are infinitely many solutions among which we want to pick the one that suits us the best, but I don't understand how.

Could you please explain me the method used in this blog?