How to find an optimum distance between 2 lines? In the below graph there are 4 series of points. These points are symmetric respect to $OX$ axis and also with the $OY$ axis.

I have to create/to draw two parallel lines in order to include all these points in between. Then, the distance between these two lines will be the error which I need to compute.
My idea:

*

*Find out the highest point for each position on $OX$ axis.


*Find out the highest point from step 1.


*Compute the slope from the point found at step 2 to the points from step 1.


*Find out the minimum slope


*We have 2 points: $A1(x_{1}, y_{1})$ and $B1(x_{2}, y_{2})$ marked with blue circle on my picture. Having these 2 points and knowing that the points are symmetric we can conclude also that the second line, parallel with the first one will pass through $A2(-x_{1}, -y_{1})$ and $B2(-x_{2},-y_{2})$ marked with red.


*Now, it can be computed the distance between these 2 lines
BUT there is also another idea better than mine, I suppose.
I compute this error using only 4 points, but every point on the graph has its own weight and importance.
So, I am thinking somehow to take into consideration all these points. Maybe it is an optimization/minimization problem.

The two lines can be parameterized as $y=ax+b$ and $y=ax-b$. The distance between the lines is given by $2|b| / \sqrt{a^2+1}$. You are therefore interested in solving
\begin{align}
\min_{a,b} \quad & \frac{2b}{\sqrt{a^2+1}} \\
\text{s.t.} \quad & ax_i+b \geq y_i \quad i=1,\ldots,n \\
& ax_i-b \leq y_i \quad i=1,\ldots,n
\end{align}
The constraints ensure that the lines $y=ax+b$ and $y=ax-b$ are above and below the datapoints $(y_i,x_i)_{i=1}^n$, respectively (so you know $|b|=b$). The objective function is not convex in $a$ (and the constraints make it difficult to do a nonlinear reparameterization to make it convex). The only thing working in your favor is that the problem only has three variables. BARON will have no problem solving this to optimality. You could do some preprocessing and for each constraint only include the extreme datapoints (for each $x$ only include the highest point for the first constraint, and the lowest point for the second constraint).
