I have 4 linear functions defined on $[x_1, x_2]$:
$$f:x \mapsto \alpha_f \cdot x + \beta_f ~~~~~~~~ f':x \mapsto \alpha_f \cdot x + \beta_f + \gamma_f$$
$$g:x \mapsto \alpha_g \cdot x + \beta_g ~~~~~~~~ g':x \mapsto \alpha_g \cdot x + \beta_g + \gamma_g$$
$$\alpha_f, \alpha_g, \beta_f, \beta_g \in \mathbb{R}, ~~~~\gamma_f, \gamma_g \in \mathbb{R}^{+*}$$
Let us call $\mathcal{A}_f$ (drawn in green in the picture below) and $\mathcal{A}_g$ (drawn in red) the following areas:
$$\mathcal{A}_f = \{(x,y)\in [x_1,x_2]\times\mathbb{R}, ~~f(x)\leq y \leq f'(x)\}$$
$$\mathcal{A}_g = \{(x,y)\in [x_1,x_2]\times\mathbb{R}, ~~g(x)\leq y \leq g'(x)\}$$
Let $\mathcal{A} = \mathcal{A}_f \cap \mathcal{A}_g$ be the intersection of the two previous areas.
I want to compute the integral over $\mathcal{A}$ of the function $H:\mathcal{A}\subset\mathbb{R}^2\rightarrow \mathbb{R}$, defined as follow:
$(x,y) \mapsto k\cdot (f'(x)-y), ~~~~k>0$
The goal is to design an algorithm to compute the value. I know hot to find the value with a lot of ifs (is $g$ above $f$? etc.) but I feel like there may be a simpler analytic solution I cannot get my hands on.
A possible physical interpretation of the problem is the following:
Assume in the 3D world, the $x$ axis is horizontal, $y$ axis is vertical (as represented on the picture), and $z$ is a third (horizontal) axis so that $(x,y,z)$ is an orthonormal set.
The surface $z=cst$ of the picture represents a contact surface between two (full) fluid containers, in contact only through $\mathcal{A}$. With $k=\rho\cdot g$, what we are looking for is the pressure force applied by the fluid in one container (the green one) on the fluid of the second (the red one).
For the sake of completeness, let us note that the actual inputs of the problem are the 8 intersection points between $x=x_1$ or $x=x_2$ on the one hand, and $f$, $f'$, $g$, $g'$ on the other hand (from which it is trivial to compute the $\alpha$s, $\beta$s and $\gamma$s).
