# Finding endpoints of an orthogonal segment

Imagine following scenario:

There is a line segment $|AB|$, point $N$ (somewhere on the line), and a distance $k$.

Now I would like to find coordinates of endpoints of a line segment $|CD|$ that is orthogonal to $|AB|$, passes through point $N$ and the distance between $C$ and $N$ (resp. $D$ and $N$) is $k$.

My approach:

(Let's ignore point $D$, because the solution is principially the same.)

First I calculate the sides of the $ANC$ triangle

$$d = \|N - A\| \\ h = \sqrt{d^2 + k^2}$$

Then angles of $CAN$ and $BAy$ triangles.

$$\alpha = \arctan \left( \frac{k}{d} \right) \\ \beta = \arctan \left( \frac{B_y - A_y}{B_x-A_x} \right)$$

And from there I can get the coordinates of point $C$.

$$C_x = h \cdot \cos \left(\alpha + \beta \right)\\ C_y = h \cdot \sin \left(\alpha + \beta \right)\\$$

My question:

While the above solution works, it feels very heavy-handed and built just from geometric primitives.

So my question is whether this is possible to do in some cleaner, straight-forward manner with linear algebra. Perhaps I could compute the normal vector and then somehow move it and expand/mirror it?

If $\vec{AB}=(u,v)$, then vector $(-v,u)$ is orthogonal to $\vec{AB}$, so that $$\vec{CN}={k\over\sqrt{u^2+v^2}}(-v,u).$$
• Excellent! This is so much nicer. :-) (Also to truly answer the question it would be $C = N + CN$, but that is just a minor detail). – Peter Uhnak Oct 23 '15 at 9:58
• Yes, and of course $D=N-\vec{CN}$. – Aretino Oct 23 '15 at 10:25