In Three.js, I have an easy method for finding the distance between a point (being the location of my camera) and a line that extends infinitely. However, what I really need is to find the distance between a point and a single line segment made from two points. Note: I'm using Three.js which has 3 spacial dimensions: x, y and z.
Here's the point to line segment formula I'm using with Three.js:
var A = lineVertex1.clone()
var B = lineVertex2.clone()
var D = B.clone().sub( A ).normalize();
var d = camera.position.clone().sub( A ).dot( D );
var X = A.clone().add( D.clone().multiplyScalar( d ) );
var distance = camera.position.distanceTo( X );