While not exactly what the OP wants, I would suggest the coordinate approach. Then the "triangle equation" becomes a circle equation in the form $x^2+y^2=R^2$ which completely defines a circle centered at the point $(0,0)$.
Because of the corners, there's no such nice equation for a square. But we can make some "square-like" shapes in a similar way using the equation:
$$x^{2n}+y^{2n}=R^{2n}, \qquad n>1$$
Here's an illustration for a few $n$, starting with a circle:
"But none of these are squares!" - anyone would say, and be right.
To define a square we can't just use a single equation. We'd have to deal with the absolute value function.
For example, here's a square with the diagonal $D$, rotated by $\pi/4$:
$$|x|+|y|=D$$
We can easily rotate this one right back, and expand it so it fits with the others:
$$|x+y|+|x-y|=a$$
Where $a$ is now the length of the side.
For a rectangle (the edited question) we just need to scale one of the coordinates. For a general rectangle with the sides $a$ and $b$ we have:
$$\left|\frac{x}{a}+\frac{y}{b} \right|+\left|\frac{x}{a}-\frac{y}{b} \right|=1$$
To get rid of the absolute value we can try squaring twice:
$$\left(\frac{x}{a}+\frac{y}{b} \right)^2+\left(\frac{x}{a}-\frac{y}{b} \right)^2+2\left|\frac{x^2}{a^2}-\frac{y^2}{b^2} \right|=1$$
$$\left(\left(\frac{x}{a}+\frac{y}{b} \right)^2+\left(\frac{x}{a}-\frac{y}{b} \right)^2-1\right)^2=4\left(\frac{x^2}{a^2}-\frac{y^2}{b^2} \right)^2$$
Unfortunately, as it often happens with squaring, we get extra solutions (the dashed lines), which don't lie on the original rectangle:
We are going to introduce a new coordinate system $x'Oy'$ like shown in Fig. 1. If we are able to calculate coordinates of point $P(x'_P, y'_P)$ in that coordinate systen - we are done because:
$$x_O=-x'_P, \ \ y_O=-y'_P\tag{1}$$
Step 1:
Find coordinates of points $A,B,C,D$ in $x'Oy'$ coordinate system:
$$A: x'_1=d_1\cos\alpha, \ y'_1=d_1\sin\alpha$$
$$D: x'_2=d_4\cos(\alpha+90^\circ), \ y'_2=d_4\sin(\alpha+90^\circ)$$
$$B: x'_3=d_3\cos(\alpha+180^\circ), \ y'_3=d_3\sin(\alpha+180^\circ)$$
$$C: x'_4=d_2\cos(\alpha+270^\circ), \ y'_4=d_2\sin(\alpha+270^\circ)$$
Step 2:
Calculate the following values:
$$x'_{\min}=\min(x_1, x_2, x_3, x_4)$$
$$x'_{\max}=\max(x_1, x_2, x_3, x_4)$$
$$y'_{\min}=\min(y_1, y_2, y_3, y_4)$$
$$y'_{\max}=\max(y_1, y_2, y_3, y_4)$$
Step 3:
Find the bottom left corner $P'(x'_{P'}, y'_{P'})$ of the bounding rectangle (shown in blue color) and calculate the width $w$ and height $h$ of the bounding rectangle:
$$x'_{P'}=x'_\min$$
$$y'_{P'}=y'_\min$$
$$w=x'_\max-x'_\min$$
$$h=y'_\max-y'_\min$$
Step 4:
If $h=w=L$ we are done (see Fig. 2) because the blue rectangle is actually our bounding square of length $L$, the points $P$ and $P'$ are identical and $x'_{P}=x'_{P'}$, $y'_{P}=y'_{P'}$. Just apply (1) and you have $x_O, y_O$.
Step 5:
Needed only if $w<L$. In this case your blue rectangle is narrower than the square and it is possible that points $P$ and $P'$ are not identical. In other words, you have to expand the blue rectangle either to the left or to the right to match the original square.
If the blue rectangle has to be expanded to the right, it won't impact the position of point $P'$ and in this case:
$$x'_P=x'_{P'}$$
The point $P'$ moves only if you have to expand your rectangle to the left. Such situation is presented in Fig. 3. Obviously:
$$x'_P=x'_{P'}-(L-w)$$
Now apply (1) and you have $x_O$.
How to recognize that expansion to the left is needed? Take a look at Fig. 3 again. You cannot move the right side of the blue rectangle more to the right because that side has points $A$ and $C$ on it and that points are not corners. If you moved that side to the right, endpoints of $d_1$ and $d_2$ would be no longer "attached" to the right side. On the contrary, there is no non-corner point on the left side of the blue rectangle so you can freely move the left side further to the left and still have endpoints $A,B,C,D$ "attached" to sides of the square.
You can detect if there is a point $(x_i, y_i)$ on the left side of the blue rectangle that is blocking expansion to the left with the following condition:
$$x_i=x_\min \ \land \ y_i \ne y_\min \ \land \ y_i \ \ne y_\max$$
Expansion to the left is not possible if this condition is satisfied for any $i=1,2,3,4$
Step 6:
Needed only if $h<L$. In this case your blue rectangle is shorter than the square and it is possible that points $P$ and $P'$ are not identical. In other words, you have to expand the blue rectangle either upwards or downwards to match the original square.
If the blue rectangle has to be expanded upwards, it won't impact the position of point $P'$:
$$y'_P=y'_{P'}$$
The point $P'$ moves only if you have to expand your rectangle downwards. Such situation is presented in Fig. 1. Obviously:
$$y'_P=y'_{P'}-(L-h)$$
Now apply (1) and you have $y_O$.
How to recognize that expansion downwards is needed? Take a look at Fig. 1 again. You cannot move the top side of the blue rectangle upwards because that side has point $D$ on it and that point is not a corner. If you moved that side upwards, endpoint of $d_4$ would be no longer "attached" to the top side. On the contrary, there is no non-corner point on the bottom side of the blue rectangle so you can freely move the bottom side further down and still have endpoints $A,B,C,D$ "attached" to sides of the square.
You can detect if there is a point $(x_i, y_i)$ on the bottom side that is blocking expansion downwards with the following condition:
$$y_i=y_\min \ \land \ x_i \ne x_\min \ \land \ x_i \ \ne x_\max$$
Expansion downwards is not possible if this condition is satisfied for any $i=1,2,3,4$
Important note
Steps shown above can be transformed into a fairly simple and efficient software code. However, have in mind that your sensors have limited precision so something that is strictly equal in mathematics (like $L=w$) is just approximately equal in the real world. In the real world, $L$ will be always different from $w,h$ because we calculate the last two values from sensor readings.
So if you want to check if $L=w$, your code should actually test for:
$$|L-w|<\delta$$
...where $\delta$ is some small value adjusted for the precision of your sensors.
Best Answer
If you take the graph of $y = x$, the region under the graph between $0$ and $t$ is half of a square of side length $t$, and $\int_0^t x \, \mathrm{d}x = \frac{t^2}{2}$. So some sort of answer is "because the gradient of the parabola is linear and thus carves out half a rectangle".