DEpending on the accuracy you want/need, JavaScript is probably the easiest way to go.

A super accruate and reliable implementation is QUITE difficult.