News for hackers. Stuff that matters.
Re:Coding Horror: Should Competent Programmers be "Mathemati... by lbrandy on Wednesday April 01, 2009 @10:35PM (#542831)
I got bad news. The question was to find the distance between a point and a line SEGMENT.

Luckily, since you know some math, and you understand what a dot product is, and how it relates to a projection, you can trivially extend your solution by checking to make sure Q is on AB, and then adjusting your answer if its not.

:)

Re:Coding Horror: Should Competent Programmers be "Mathemati... by palish on Wednesday April 01, 2009 @11:16PM (#542851)
Ahh, yes. Good catch. In the algorithm, simply clamp AQ_len to be >= 0.0 and <= AB_len. (Notice that you compute AB_len as a side effect of normalizing AB.)