<s>[INST] Hardcore integral with absolute value Is it possible to solve this integral?
$$\int_0^1\int_0^1\frac{{(y-y_1-\frac{(x-x_1)(y_2-y_1)}{x_2-x_1})(y-y_1-\frac{(x-x_1)(y_3-y_1)}{x_3-x_1})(y-y_3-\frac{(x-x_3)(y_2-y_3)}{x_2-x_3})}}{|{(y-y_1-\frac{(x-x_1)(y_2-y_1)}{x_2-x_1})(y-y_1-\frac{(x-x_1)(y_3-y_1)}{x_3-x_1})(y-y_3-\frac{(x-x_3)(y_2-y_3)}{x_2-x_3})}|}dxdy$$
$x_1,x_2,x_3,y_1,y_2,y_3\in[0,1]$
It would be like adding red area and subtracting green area

 [/INST] Label the triangle vertices $v_{1} = (x_{1}, y_{1})$, $v_{2} = (x_{2}, y_{2})$, $v_{3} = (x_{3}, y_{3})$, counterclockwise (say), so that the line $\ell_{ij} = \overline{v_{i} v_{j}}$ divides the square into two regions; call the "right-hand" region (not containing the central triangle) $A_{ij}$. Let $a_{ij}$ denote the area of $A_{ij}$, and $a_{0}$ the area of the central triangle.
Up to a sign, the integral is equal to
$$
4a_{0} - 3 + 2(a_{12} + a_{23} + a_{31}).
$$
In a bit more detail, the function
$$
f_{ij}(x, y) = y - y_{i} - \frac{y_{j} - y_{i}}{x_{j} - x_{i}}(x - x_{i})
$$
is (i) only defined if $x_{i} \neq x_{j}$, i.e., if $v_{i}$ and $v_{j}$ do not lie on a vertical line; (ii) positive above the line and negative below (rather than positive to the right of the oriented segment and negative to the left). As long as no two of the vertices lie on a vertical line, however, the integral
$$
\int_{0}^{1} \int_{0}^{1}
  \frac{f_{12}(x, y) f_{23}(x, y) f_{31}(x, y)}
       {|f_{12}(x, y) f_{23}(x, y) f_{31}(x, y)|}\, dx\, dy
$$
is equal in absolute value to the expression above.

To prove this, label the areas of regions as shown, with $a_{i}$ abutting $v_{i}$ and $b_{i}$ opposite the central triangle from $v_{i}$. We have
$$
\left.
\begin{aligned}
a_{12} &= a_{1} + a_{2} + b_{3} \\
a_{23} &= a_{2} + a_{3} + b_{1} \\
a_{31} &= a_{3} + a_{1} + b_{2}
\end{aligned}\right\}
\tag{1a}
$$
and
$$
1 = a_{0} + a_{1} + a_{2} + a_{3} + b_{1} + b_{2} + b_{3}.
\tag{1b}
$$
Rearranging,
\begin{align*}
2 - 2a_{0} &= 2(a_{1} + a_{2} + a_{3}) + 2(b_{1} + b_{2} + b_{3}), \\
a_{12} + a_{23} + a_{31} &= 2(a_{1} + a_{2} + a_{3}) + b_{1} + b_{2} + b_{3}.
\end{align*}
Subtracting the second from the first,
$$
2 - 2a_{0} - (a_{12} + a_{23} + a_{31}) = b_{1} + b_{2} + b_{3}.
\tag{2}
$$
The blue area minus green area is equal to
\begin{align*}
a_{0} + a_{1} + a_{2} + a_{3} - (b_{1} + b_{2} + b_{3})
  &= 1 - 2(b_{1} + b_{2} + b_{3}) \\
  &= 1 - 2\bigl[2 - 2a_{0} - (a_{12} + a_{23} + a_{31})\bigr] \\
  &= 4a_{0} - 3 + 2(a_{12} + a_{23} + a_{31}).
\end{align*}
</s>