Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Double integral over triangle with known nodes

  1. Jan 17, 2012 #1
    I am wondering is there any general analytic solutions to the following integrals

    First moment of area

    Second moment of area)

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


  2. jcsd
  3. Jan 18, 2012 #2


    User Avatar
    Science Advisor

    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
    [tex]\int_{x= x1}^{x2}\int_{y= y1+ ((y3- y1)/(x3- x1))(x- x1)}^{y1+ ((y2-y1)/(x2-x1))(x- x1)}f(x,y) dydx[/tex]
    where f(x,y) is x, y, x^2, y^2, or xy.
  4. Jan 19, 2012 #3
    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:

    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
    A=(x2*y1 - x1*y2 + x1*y3 - x3*y1 - x2*y3 + x3*y2)/2;
    %A is area (watch for orientation of nodes clockwise/counterclockwise

    Let me know what you think
  5. Jan 21, 2012 #4
    %this way you went form x,y to u,v

    %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)

    %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

    %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