Inverse kinematics to allow the end of an articulated arm to follow the mouse pointer. Grab the ball by moving the mouse pointer to it and click the mouse button to grab it. Try grabbing the ball while it's moving. To see the geometric shapes used for the angle calculations, press "g". According to Wikipedia: "Inverse Kinematics is the mathematical process of calculating the variable joint parameters needed to place the end of a kinematic chain, such as a robot manipulator or animation character's skeleton, in a given position and orientation relative to the start of the chain."
I remixed this to add a gripper at the end of the arm and something to grab. I also modified the calculations a little to allow an offset from 0,0. This is my first attempt at more than one joint. The calculations for the angles for the 3 segment arm are actually simpler than the calculations for the 2 segment arm.