# Integral of a quadratic function over a triangle

Consider a triangle given its three vertices in 3 space, $a, b, c$. Is there an expression or a way to calculate it better then monte carlo, for computing the the integral over this triangle, of the product of the linear function which is 1 at one vertice, and 0 at the two others and another which is 1 at some vertice and 0 at the two others.

So input is the three vertice is three space, and the two vertices at which the two functions is 1.

Edit: In this question it is seen that if the two vertices chosen for the two functions are not equal there is a simple expression, namely Area/12, is there one when the two vertices are the same aswell?

• You probably want to change the title of your question to match the new text. By the way, a function that is 1 at one vertex at an arbitrary position and 0 at the other two is not a "linear" function in the usual linear algebra sense but rather an "affine" function--i.e. something like $f(x)=ax+by+cz+d$. Is that what you mean? (This comment was edited.) – Rory Daulton Nov 15 '17 at 10:33
• Yes this is what I mean, except that we are in 3 space, so this function has a dz too. – KALLE DA BAWS Nov 15 '17 at 10:36
• Since the function will be a polynomial, and the area you are integrating is a triangle, it should be possible to parametrize the triangle and write out the integral you need as a double integral... – 5xum Nov 15 '17 at 10:37
• Answer is $Area*(1+delta(i,j))/12$ – KALLE DA BAWS Nov 15 '17 at 12:32

Hint:

Use an affine coordinate transform and set

$$p=(x_0,x_1,x_2)=a+u(b-a)+v(c-a).$$

The Jacobian of the transformation is the determinant of the matrix formed with $b-a$ and $c-a$, a constant (the area of the parallelogram built on $a,b,c$).

Then

$$\iint_T \,dx_i\,dx_j=J\int_{u=0}^1\int_{v=0}^u\,dv\,du.$$

$$\iint_T x_i\,dx_i\,dx_j=J\int_{u=0}^1\int_{v=0}^u(a_i+u(b_i-a_i))\,dv\,du.$$

$$\iint_T x_ix_j\,dx_i\,dx_j=J\int_{u=0}^1\int_{v=0}^u(a_i+u(b_i-a_i))(a_j+v(c_j-a_j))\,dv\,du.$$

We have

$$\int_{u=0}^1\int_{v=0}^u1\,dv\,du=\frac12,\\ \int_{u=0}^1\int_{v=0}^uu\,dv\,du=\frac13,\\ \int_{u=0}^1\int_{v=0}^uv\,dv\,du=\frac16,\\ \int_{u=0}^1\int_{v=0}^uuv\,dv\,du=\frac18.\\$$

By combining these results, you can easily obtain the integral of any quadratic function of $p$, such as yours,

$$f(p)=\frac{((p-a)\times(p-b))^2}{((c-a)\times(c-b))^2}=\frac{(p\times(b-a)+a\times b)^2}{((c-a)\times(c-b))^2}.$$

• Sorry, what is the meaning of f(p) and this expression? – KALLE DA BAWS Nov 15 '17 at 11:12
• @JustMe: its your function. $a,b\to0,c\to1$. – Yves Daoust Nov 15 '17 at 11:18