# Most accurate linear approximation for two lines

Consider two lines defined by:

\begin{aligned}y_1 &= m_1 x + b_1\\y_2 &= m_2 x + b_2\end{aligned}

where for the sake of argument, the domain of both lines is the same and everything is a real number.

Is there an analytical solution to a new line, $y_3$, that minimizes the error between the original two lines? For example, $m_3 = \frac{1}{2}(m_1+m_2)$ and $b_3 = \frac{1}{2}(b_1+b_2)$. This would work for lines where $m_1 = -m_2$ and $b_1 = -b_2$. However, for two parallel lines averaging the intercepts would be great but the slope would need to be unchanged.

Is there a general expression for the new line that best approximates the original two lines?

• How are you defining error? – Peter Woolfitt May 28 '14 at 0:29
• I'd go with $ax + by + c = 0$ form of the equations, so you cover vertical lines too. – Kaster May 28 '14 at 2:29

By symmetry for non-parallel lines the smallest error is given by the line that passes through the point of their intersection and bisects the angle between them. Recall that $m=\tan\theta$, where $\theta$ is the angle between the line and the $x$-axis. To get the bisector slope you need to average angles, not slopes, i.e. $m_3=\tan\theta_3:=\tan\frac{\theta_1+\theta_2}{2}$. Expressing $m$ in terms of $m_i=\tan\theta_i$ doesn't look pretty but can be done using trig formulas. Then solving for the intersection point gives you some $(x_*,y_*)$, and the slope-point equation of the bisector line is $y-y_*=m(x-x_*)$. You can see that the new intercept is $b_3=y_*-m_3x_*$, so it will not be any prettier than $m_3$.