# Double integral over triangle with known nodes

1. Jan 17, 2012

### Zhigang Wei

I am wondering is there any general analytic solutions to the following integrals

First moment of area
Integral(xdxdy)
Integral(ydxdy)

Second moment of area)
Integral(x^2dxdy)
Integral(y^2dxdy)
Integral(xydxdy)

Over the triangle (x1,y1) (x2,y2) (x3,y3)

thanks

Wei

2. Jan 18, 2012

### HallsofIvy

It looks like basic Calculus III with some attention to different cases (x1< x2< xc3 or x1< x3< x2, etc.).

Assuming that x1< x2< x3 and that y2 is larger than either y1 or y3, We can integrate from the line between (x1, y1) and (x3, y3) to the line between (x1, y1) to (x2, y2) for x going from x1 to x2, then from the line between (x1, y1) and (x3,y3) to the line between (x2,y2) and (x3,y3).

The line between (x1, y1) and (x3, y3) is given by y= y1+ ((y3- y1)/(x3-x1))(x- x1) and the line between (x1, y1) and (x2, y2) is given by y= y1+ ((y2- y1)/(x2- x1))(x- x1) so that first integral would be
$$\int_{x= x1}^{x2}\int_{y= y1+ ((y3- y1)/(x3- x1))(x- x1)}^{y1+ ((y2-y1)/(x2-x1))(x- x1)}f(x,y) dydx$$
where f(x,y) is x, y, x^2, y^2, or xy.

3. Jan 19, 2012

### dragozarkovic

I suppose this will work for given type of triangle, I am not going to check it. But most people need universal solution. I took me a lot of time to get to this and it works (all is written in Matlab code).

Lets say you have triangle (x1,y1) (x2,y2) (x3,y3) and you want to calculate integral I=x^2+y^2 over it.

First you need to declare:
x=(1-u)*x1+u*((1-v)*x2+v*x3);
y=(1-u)*y1+u*((1-v)*y2+v*y3);

Then simple do integral I1=u*I(v) from 0 to 1, and then I2=I1(v) from 0 to 1. And then you have to multiply result by 2 areas of triangle.

This works great for me i tested it, and I get great results. Matlab code would be something like this:

syms x1 y1 x2 y2 x3 y3 x y u v
x=(1-u)*x1+u*((1-v)*x2+v*x3);
y=(1-u)*y1+u*((1-v)*y2+v*y3);
A=(x2*y1 - x1*y2 + x1*y3 - x3*y1 - x2*y3 + x3*y2)/2;
%A is area (watch for orientation of nodes clockwise/counterclockwise
I=x^2+y^2;
I2=2*A*int(int(u*I,v,0,1),u,0,1);

Let me know what you think

4. Jan 21, 2012

### dragozarkovic

x=(1-u)*x1+u*((1-v)*x2+v*x3);
y=(1-u)*y1+u*((1-v)*y2+v*y3);
%this way you went form x,y to u,v

I=x^2+y^2;
%concerning first change from x,y to u,v I should be:
%I=(u*(v*x3 - x2*(v - 1)) - x1*(u - 1))^2 + (u*(v*y3 - y2*(v - 1)) - y1*(u - 1))^2

A=(x2*y1 - x1*y2 + x1*y3 - x3*y1 - x2*y3 + x3*y2)/2;
%A is area of triangle (watch for orientation of nodes clockwise/counterclockwise not to get negative area)

I1=int(u*I,v,0,1);
%first integral ∫u*I(v) from 0 to 1
%solution is:
%I1=(u^3*(x2 - x3)^2)/3 + (u^3*(y2 - y3)^2)/3 + u*(u*x2 - x1*(u - 1))^2 + u*(u*y2 - y1*(u - 1))^2 - u^2*(u*x2 - x1*(u - 1))*(x2 - x3) - u^2*(u*y2 - y1*(u - 1))*(y2 - y3)
%notice that there is no longer v

I2=2*A*int(I1,u,0,1);
%twice area of triangle times second integral ∫I1(u) from 0 to 1
%solution is:
%I2=-(x1*y2 - x2*y1 - x1*y3 + x3*y1 + x2*y3 - x3*y2)*(x1^2/12 + (x1*x2)/12 + %(x1*x3)/12 + x2^2/12 + (x2*x3)/12 + x3^2/12 + y1^2/12 + (y1*y2)/12 + (y1*y3)/12 + y2^2/12 + (y2*y3)/12 + y3^2/12);
%finally you got solution without x, y, u or v just through nodes of triangle

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook