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 ?