2
$\begingroup$

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?

  • 0
    @anon Thanks! That was all I needed (you could put that as an answer).2012-05-02

2 Answers 2

1

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.

  • 0
    @AymanHourieh: Fixed now.2012-05-02
1

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*}