Keywords: Math, point to line, perpendicular distance

Known location of points A, B and C, calculate the shortest distance (perpendicular distance) of point A and line BC.


double computeDistance(vec3 A, vec3 B, vec3 C) 
    vec3 d = (C - B) / C.distance(B);
    vec3 v = A - B;
    double t =;
    vec3 P = B + t * d;
    return P.distance(A);


He was still too young to know that the heart's memory eliminates the bad and magnifies the good, and that thanks to this artifice we manage to endure the burden of the past. ― Gabriel García Márquez, Love in the Time of Cholera