Jo
I can't run your code right now, I'll do it since I can. About the points, one may be the point you are interested, and the other two may be the edges of your line. You must calculate de distance from one tho another (you have one, the length of the segment, so it's just two calculations). After that, you use the 3 sides in Heron's formula, to get the distance of each point to the line.
I assure you, it's not difficult to do.
Good luck
Rodrigo Salvador