TITLE: Equation of angle bisector, given the equations of two lines in 2D
QUESTION [11 upvotes]: I have two lines in 2D expressed with general equation (or implicit equation):
First line: $a_1x+b_1y=c_1 \qquad(1)$
Second line: $a_2x+b_2y=c_2 \qquad(2)$
If the two lines are intersecting I will need to find the equation of the angle bisector line. 
If the two lines are parallel I will need to find the equation of the "middle" line (I do not know the "right" name for this line, maybe "medial axis"?). 
For example if the two parallel lines are $x=1$ and $x=-1$ then the "middle" line will be $x=0$.
I found a snippet of code where the angle bisector line is
$(a_1+a_2)x+(b_1+b_2)y=c_1+c_2 \qquad(3)$
but I do not understand why (apart from the simple cases of vertical or horizontal parallel lines).

REPLY [12 votes]: I'd say that Américo's answer has pretty well covered the algebraic solution, but I think there's some elegance to using trigonometry here.  Let's say that your two lines are $y=m_1x+b_1$ and $y=m_2x+b_2$ and that they intersect at $(x_0,y_0)$ (or, rather, that this is a point on the angle bisector).  I'm not really following directly from your original problem statement, but rather just trying to give an idea of the technique.
The directed acute angles formed by the lines and the positive $x$-axis are $\theta_1=\arctan(m_1)$ and $\theta_2=\arctan(m_2)$, so the directed acute angle formed by one angle bisector and the positive $x$-axis is $\theta_3=\frac{\theta_1+\theta_2}{2}$, so it has slope $m_3=\tan\theta_3=\tan\left(\frac{\arctan(m_1)+\arctan(m_2)}{2}\right)$.
Now, an equation for this angle bisector is $y-y_0=m_3(x-x_0)$ or $$y-y_0=\tan\left(\frac{\arctan(m_1)+\arctan(m_2)}{2}\right)(x-x_0).$$  The other angle bisector would be perpendicular to this one, so it would have slope $-\frac{1}{m_3}=-\cot\left(\frac{\arctan(m_1)+\arctan(m_2)}{2}\right)$ and an equation for it would be $$y-y_0=-\cot\left(\frac{\arctan(m_1)+\arctan(m_2)}{2}\right)(x-x_0).$$
As it happens, the expression for $m_3$ can be simplified to a purely-algebraic expression (by applying trig identities, etc.): $$m_3=\frac{m_1m_2-1+\sqrt{m_1^2+1}\sqrt{m_2^2+1}}{m_1+m_2}$$
With this, the two lines become
$$y-y_0=\frac{m_1m_2-1+\sqrt{m_1^2+1}\sqrt{m_2^2+1}}{m_1+m_2}(x-x_0)$$
and
$$y-y_0=-\frac{m_1+m_2}{m_1m_2-1+\sqrt{m_1^2+1}\sqrt{m_2^2+1}}(x-x_0).$$