2

I would like to merge two lines having a y = mx + b equation with very close angles. I am simply comparing their angle difference, then I create a new line passing through the middle of these by calculating their m and b average.

This method succeeds when the algorithm encounters two lines with positive values.

The segment on the right has it's m variable set to 0.034, and b variable set to 109.49. The segment on the left has it's m variable set to 0.017, and b variable set to 128.72.

The averaging method gives a result of m being 0.026 and b with the value of 119.105.

But I am actually stuck in the case where there are two diagonal lines, where one of them has a negative m variable.

The segment on the top right has it's m variable set to 26.837, and b variable set to -44172.254. The segment on the bottom left has it's m variable set to -19.648, and b variable set to 29264.59.

The averaging method gives a result of m being 3.5945 and b with the value of -7453.8324.

Is there a more efficient method of solving this problem ?

  • $m_1 = tan(\alpha_1)$ and $m_2 = tan(\alpha_2)$. You want to get average of two angles, i.e. $\alpha = (\alpha_1 + \alpha_2)/2$, however when you average m's you get $m = (m_1 + m_2)/2 = tan(\alpha) = (tan(\alpha_1)+tan(\alpha_2))/2$. So if you need angle average you need to do: $m = tan(\alpha) = tan((\arctan(m_1) + \arctan(m_2))/2)$. Once you find your new $m$ you adjust your new $b$ so that your new line passes through the intersection of the previous two lines. – Pasha Dec 12 '19 at 13:25
  • 1
    This question gives a formula for computing the bisectors of a pair of lines. This answer explains how to choose the sign to get the acute bisector, which is what you’re looking for. The formulas do involve square roots, but no trig or inverse trig functions. – amd Dec 13 '19 at 04:44
  • Thanks a lot for your help! It fits perfectly with that I need! – Axel Isouard Dec 17 '19 at 11:21

0 Answers0