Minimal Square Containing Triangle PQR

This applet shows how finding the minimal square containing a given triangle can be reduced to placing the longest and second side as vectors u and v from the origin and calculating points of intersections of four difference functions choosing the best solution among them.
You can drag the points P, Q and R to change the original and you can rotate the copy by dragging the point labeled "rotate". The green triangle and square show the optimal solution for the given triangle.