# Thread: finding the "end points" of an orthogonal line giving the lenght

1. ## finding the "end points" of an orthogonal line giving the lenght

First of all sorry if am posting on the wrong sub forum or the title is a little misleading..

Am working on a software right now, and am really embarrassed that I dont remember the basic mathematic to solve this problem.

this is the thing, for any given line (lets say L1) I need to create two orthogonal lines (L2 and L3) with length C, at the two ends of L1

What I have is P1, P2 and C, and what I need is P3(x3, y3), P4(x4, y4) etc

2. Hello, axl456!

This takes quite a bit of work . . .

$\displaystyle \text{For any given line }L_1\text{, I need to create two orthogonal lines}$
$\displaystyle L_2\text{ and }L_3\text{ with length }c\text{ at the ends of }L_1.$

We have points $\displaystyle P_1(x_1,y_1)$ and $\displaystyle P_2(x_2,y_2).$

Let: $\displaystyle \,\theta$ = the angle at $\displaystyle \,P_1.$

Let: $\displaystyle R \:=\:\overline{P_1P_2} \:=\:\sqrt{(x_2-x_1)^2 + (y_2-y_1)^2}$

Code:

|
|                    (x2,y2)
|                       ♥ P2
|             R     *   |
|               *       | y2-y1
|           *  @        |
|    P1 ♥---------------*
|    (x1,y1)  x2-x1
|
- - + - - - - - - - - - - - - - - -
|


Then we have: .$\displaystyle \begin{Bmatrix}\sin\theta &=& \dfrac{y_2-y_1}{R} \\ \\[-4mm] \cos\theta &=& \dfrac{x_2-x_1}{R}\end{Bmatrix}$

Let:. . $\displaystyle \begin{Bmatrix} \Delta x &=& \frac{1}{2}c\sin\theta \\ \\[-4mm] \Delta y &=& \frac{1}{2}c\cos\theta \end{Bmatrix}$

Code:

|                   C
|                   *
|                   |\
|                   | \
|   A               |  \  ∆x
|   *               .---♥---.
|   |\              *  P2\  |
| ∆y| \         *         \ | ∆y
|   |  \P1  *              \|
|   .---♥---.               *
|     ∆x \  |               D
|         \ |
|          \|
|           *
|           B
|
- - + - - - - - - - - - - - - - - -
|

To move from $\displaystyle \,P_1$ to $\displaystyle \,A$: .move left $\displaystyle \Delta x$ and up $\displaystyle \Delta y.$
. . Hence: .$\displaystyle A(x_1\! -\! \Delta x,\;y_1 \!+\! \Delta y)$

To move from $\displaystyle \,P_1$ to $\displaystyle \,B$: .move right $\displaystyle \Delta x$ and down $\displaystyle \Delta y.$
. . Hence: .$\displaystyle B(x_1\! +\! \Delta x,\;y_1\!-\!\Delta y)$

To move from $\displaystyle \,P_2$ to $\displaystyle \,C$: .move left $\displaystyle \Delta x$ and up $\displaystyle \Delta y.$
. . Hence: .$\displaystyle C(x_2\!-\!\Delta x,\;y_2\!+\!\Delta y)$

To move from $\displaystyle \,P_2$ to $\displaystyle \,D$: .move right $\displaystyle \Delta x$ and down $\displaystyle \Delta y.$
. . Hence: .$\displaystyle D(x_2\!+\!\Delta x,\;y_2\!-\!\Delta y)$

While waiting for a reply, I keep analyzing it and found another solution..

what I did is simple use the slope and distance equation:

$\displaystyle D \:=\:\sqrt{(x-x0)^2 + (y-yo)^2}$

$\displaystyle m = (y-y0)/(x-x0)$

being (x, y) the point I need, and (x0, y0) the points I have.
From those two I got this equation:

$\displaystyle x^2 - 2xx0 + xo^2 -(\dfrac{d^2}{1 + m^2}) = 0$

I solve it with the quadratic formula, and got 2 results (the two equidistant points that form the new line)

this is the result:

Again thank you!..