First of all: my knowledge in mathematics is a bit rusty, so no matter how simple my question is, I afraid I in every case need a somewhat detailed answer:
I have a line from coordinates (x1,y1) to (x2,y2). Now I want to prepend a second line (x0,y0) to (x1,y1) before this one, but it should have a 90 degree angle to the first one.
Any idea how I can calculate my coordinates (x0,y0) so that the two lines form a right angle?
Finally all should be done in C programming language but I think this does not matter for this specific question.
Thanks for your patience!
When two lines are perpendicular, their slopes (denoted by $m$) are negative reciprocals. In general, you can calculate $m$ by using the following formula.
$$m = \frac{\Delta y}{\Delta x} = \frac{y_2-y_1}{x_2-x_1}$$
Call the slope of the first line $m_1$ and the slope of the second line $m_2$.
$$m_1 = \frac{y_2-y_1}{x_2-x_1}$$
$$m_2 = \frac{y_1-y_0}{x_1-x_0}$$
Use
$$m_1 = -\frac{1}{m_2}$$
which gives
$$\frac{y_2-y_1}{x_2-x_1} = -\frac{1}{\frac{y_1-y_0}{x_1-x_0}} \implies \frac{y_2-y_1}{x_2-x_1} = \frac{x_1-x_0}{y_1-y_0}$$
and you have $(x_1, y_1)$ and $(x_2, y_2)$, so you can reach an equation for $y_0$ and $x_0$ followed by calculating for $(x_0, y_0)$, for which there are infinite possibilities.