# Distance between a line segment and a point equation

This is definitely a duplicate question but I'm not asking for a formula. I have a formula that I found somewhere but I don't understand how it works.

On a (two-dimensional) Euclidean plane, suppose you have a line segment with end points AB and a point C.

The distance of C from AB is (B.x - A.x) * (A.y - C.y) - (B.y - A.y) * (A.x - C.x)

Edit: The objective was to find the shortest distance from the line segment AB and point C, where the distance(line segment) is perpendicular to the line segment AB. We can assume that points A and B are the leftmost and rightmost points, where C is between them

Question: how does this formula meet this objective?

• There doesn't appear to be a question here! Are you asking if that final formula is correct? Since AB is a line segment, not a line there are two different cases: – user247327 Nov 6 '18 at 17:48
• It takes a little investment of time and learning effort, but you can post mathematical notation here. If you wish, I'll replace your formula with a more "mathematical" expression. However as @user247327 points out, the formula cannot be right because there is the case when the closest distance from $C$ to line segment $\overline{AB}$ reaches an endpoint and the case when it reaches the interior of $\overline{AB}$. – hardmath Nov 6 '18 at 18:04
• hardmath, if you could, that would be great. I'm not a maths student and this formula, if you could call it that, I found from code since I'm an amateur software developer – SoftwareEngineerStudent Nov 6 '18 at 18:15
• It’s going to be hard to explain how this formula computes the distance between the point and segment because it doesn’t. For a simple example like $A=(-1,0)$, $B=(1,0)$, $C=(1,1)$, this formula gives $2$, but the actual distance is quite obviously $1$. There is a formula that involves the quotient of some cross products, so I suspect that the one you have here is missing something. – amd Nov 6 '18 at 20:25