Finding the best fitting square

I have to find the best fitting square using the total least squares method. First we we had to find the best fitting rectangle using the following equations:

• s1: $c1+ax+by=0$, $a^2 +b^2 =1$
• s2: $c2−bx+ay=0$,
• s3: $c3+ax+by=0$,
• s4: $c4−bx+ay=0$,

So, s1 corresponds to side 1 with x,y being the measurements for that side (so a couple of points through which a line must be found).

Using the least squares method we have to solve:

http://i.imgur.com/0sJkR.png (not enough reputation)

I succeeded in finding the rectangle, but we also had to find the best fitting square. We were given that the distance between two parallel lines

• A: $c1+ax+by=0$, $a^2+b^2=1$
• B: $c2+ax+by=0$

is |c1-c2|. So naturally the equations have to be modified to reflect that $|c1-c3|=|c2-c4|$.

I think I have almost tried everything, I just can't find a right solution. (I tried letting c2 = c1+d and c4 = c3 +- d; I tried c1 = c2 + c3 - c4)

-