This is a relatively large problem. Try to break it up in smaller bits. Calculating distance between two points is trivial (just use the Pythagorean theorem on the coordinates), so your actual question is how to find the tips of your object.
One of the steps that might help, is skeletonizing the image. Then you can find the endpoints. The only task left to you is figuring out a way to find out which endpoints you should use.
Good luck.
