# Thread: Integrating over a parametrized triangle

1. ## (Solved) Integrating over a parametrized triangle

Hello everyone,

I'm trying to perform a double integral over a parametrized triangle as part of computing the inertia tensor of a mesh. I'll spare the details, but the end result is that I need to evaluate the integral

$\int_{v=0}^{v=1} \int_{u=0}^{u=1-v} \! \left[ (1-u-v)p_0 + up_1 + vp_2 \right] ^3 \, \mathrm{d} u \, \mathrm{d} v$

where $p_0$, $p_1$ and $p_2$ are constants (represents the x-coordinate of the triangle vertex). The integral bounds come from the triangle parametrization.

Evaluating the inside integral, I get

$= \int_{v=0}^{v=1} \left. \frac{\left[ (1-u-v)p_0 + up_1 + vp_2 \right] ^4}{4(p_1 - p_0)} \, \right|_{u=0}^{u=1-v} \mathrm{d} v$

$= \frac{1}{4(p_1 - p_0)} \int_{v=0}^{v=1} \left[ (1-v)p_1 + vp_2 \right]^4 - \left[ (1-v)p_0 + vp_2 \right]^4 \, \mathrm{d} v$

Then evaluting the outside integral:

$= \frac{1}{4(p_1 - p_0)} \left[ \left. \frac{\left[ (1-v)p_1 + vp_2 \right]^5}{5(p_2 - p_1)} - \frac{\left[ (1-v)p_0 + vp_2 \right]^5}{5(p_2 - p_0)} \right|_{v=0}^{v=1} \right]$

$= \frac{1}{4(p_1 - p_0)} \left[ \left( \frac{p_2^5}{5(p_2 - p_1)} - \frac{p_2^5}{5(p_2 - p_0)} \right) - \left( \frac{p_1^5}{5(p_2 - p_1)} - \frac{p_0^5}{5(p_2 - p_0} \right) \right]$

$= \frac{1}{20(p_1 - p_0)} \left[ \left( \frac{p_2^5 - p_1^5}{p_2 - p_1} \right) - \left( \frac{p_2^5 - p_0^5}{p_2 - p_0} \right) \right]$

$= \frac{1}{20(p_1 - p_0)} \left[(p_2^4 + p_2^3p_1 + p_2^2p_1^2 + p_2p_1^3 + p_1^4) - (p_2^4 + p_2^3p_0 + p_2^2p_0^2 + p_2p_0^3 + p_0^4) \right]$

$= \frac{1}{20(p_1 - p_0)} (p_2^3p_1 + p_2^2p_1^2 + p_2p_1^3 + p_1^4 - p_2^3p_0 - p_2^2p_0^2 - p_2p_0^3 - p_0^4)$

This resembles, but doesn't quite match my expected result,

$\frac{1}{20}(p_0^3 + p_1^3 + p_2^3 + p_0^2p_1 + p_0p_1^2 + p_0^2p_2 + p_0p_2^2 + p_1^2p_2 + p_1p_2^2 + p_0p_1p_2)$

Some parts look okay, like the $p_1^4$ and $p_0^4$ terms in the numerator might eventually factor with the $(p_1 - p_0)$ term in my denominator to at least get the correct cubic terms, but in general the denominator is giving me trouble, and I don't see where the correct result's $p_0p_1p_2$ term might come from. It feels like I've done something silly somewhere, but I can't see where. (Haven't we all been there before? >_>)

Could I trouble someone to take a look and see where things went wrong?

Edit: Found the solution- nothing was wrong, I just missed the final factorisation:

$= \frac{1}{20(p_1 - p_0)} ((p_2^3p_1 - p_2^3p_0) + (p_2^2p_1^2 - p_2^2p_0^2) + (p_2p_1^3 - p_2p_1^3) + (p_1^4 - p_0^4))$

$= \frac{1}{20(p_1 - p_0)} (p_2^3(p_1 - p_0) + p_2^2(p_1^2 - p_0^2) + p_2(p_1^3 - p_0^3) + (p_1^4 - p_0^4))$

$= \frac{1}{20(p_1 - p_0)} (p_2^3(p_1 - p_0) + p_2^2(p_1 - p_0)(p_1 + p_0) + p_2(p_1 - p_0)(p_1^2 + p_1p_0 + p_0^2) + (p_1 - p_0)(p_1^3 + p_1^2p_0 + p_1p_0^2 + p_0^3))$

$= \frac{1}{20(p_1 - p_0)} (p_1 - p_0)(p_2^3 + p_2^2(p_1 + p_0) + p_2(p_1^2 + p_1p_0 + p_0^2) + (p_1^3 + p_1^2p_0 + p_1p_0^2 + p_0^3))$

$= \frac{1}{20}(p_2^3 + p_1p_2^2 + p_0p_2^2 + p_1^2p_2 + p_1p_0p_2 + p_0^2p_2 + p_1^3 + p_1^2p_0 + p_1p_0^2 + p_0^3)$

$= \frac{1}{20}(p_0^3 + p_1^3 + p_2^3 + p_0^2p_1 + p_0p_1^2 + p_0^2p_2 + p_0p_2^2 + p_1^2p_2 + p_1p_2^2 + p_0p_1p_2)$ as required.