Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I am sure this is something completely dumb but my mathematics is, well awful, so be kind...

I know three coordinates (2D standard x and y things where the top left is 0,0 and the x increases from left to right and y increases from top to bottom) and I can plot a line between two of them and then make a third point where the intersection with the line should be 90 degrees and what I want to calculate is the length of the line that made this angle (I am sure if I could explain myself properly I would have found an answer to this already).

Here is a picture of what I mean (with some example values for the three coordinates A, B and C that are known to me):

diagram

So, how do I calculate the length marked L in the above?

I thought, well, the line L is normal to the vector A to B so I could say...

The vector from A to B is (4, 7) and therefore the normal vectors would be (-7, 4) and (7, -4) but then I am stuck - where do I go now? Am I even on the right track?

share|improve this question
2  
The red line is often called "dropping a perpendicular" in geometry. Optional reading material: en.wikipedia.org/wiki/Distance_from_a_point_to_a_line –  anon May 2 '12 at 8:13
    
@anon Thanks! That was all I needed (you could put that as an answer). –  kmp May 2 '12 at 8:19
add comment

2 Answers

up vote 1 down vote accepted

Here is the easiest way I can think of:

  • Find the normal vector for $AB$.

  • Take the dot product of the normal vector and $A$.

  • Take the dot product of the normal vector and $C$.

  • Subtract the two dot products.

  • Divide by the length of the normal vector.

The result is the length of $L$.

Per your example:

  • $N = B-A = (7, -4)$.

  • $a = N \cdot A = (1 \cdot 7) + (1 \cdot -4) = 7 - 4 = 3$.

  • $c = N \cdot C = (7 \cdot 7) + (-4 \cdot 5) = 49 - 20 = 29$.

  • $c - a = 29 - 3 = 26$.

  • $|N| = \sqrt{7^2 + 4^2} = \sqrt{49 + 16} = \sqrt{65} \approx 8.062$.

  • $26 \div 8.062 \approx 3.225$.

So $L$ is about 3.225 units long.

share|improve this answer
    
The normal vector alone isn't sufficient to find the distance. To see why, notice that all parallel lines have the same normal vector, but their distances from a fixed point change depending on where the line is located in the plane. –  Ayman Hourieh May 2 '12 at 10:25
    
You are of course correct. Give me a minute to fix my answer... –  MathematicalOrchid May 2 '12 at 10:30
    
@AymanHourieh: Fixed now. –  MathematicalOrchid May 2 '12 at 10:34
add comment

What you want a point-line distance in 2D.

Let's calculate the formula of $AB$:

$$ y-y_A = \frac{y_B-y_A}{x_B-x_A} (x-x_A) $$

Plug and simplify:

$$ 7x -4y -3 = 0 $$

Now let's use the point-line distance formula:

\begin{align*} d &= \frac{|ax_0+by_0+c|}{\sqrt{a^2+b^2}} \\ &= \frac{|7\times7+(-4)\times5+(-3)|}{\sqrt{7^2+(-4)^2}} \\ &= \frac{26}{\sqrt{65}} \approx 3.224 \end{align*}

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.