You have the right formula, provided that (x1, y1) and (x2, y2) were actually the end-points of the line. Perhaps they weren't... we certainly can't determine that by looking at your post. Also read this: ItDoesntWorkIsUseless and then post something which would help us to help you better.
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads