1

Considering a polygon with n vertices as input.

enter image description here

I need to calculate the integral of the form \[\int_A p(y) dA \] where $p(y)$ is a piecewise polynomial function of $y$.

May be if I could find the expression $b(y)$ then the integral can be calculated by: $$\int_{0}^{y_\max} p(y) b(y) dy $$

The question is : "is there a straightforward method to find $b(y)$ given the coordinates of the polygon vertices? Or is there a simpler manner to calculate the integral above?"

  • 1
    Welcome Hafid! This looks like an application of Cavalieri's principle. You can calculate the (piecewise linear) function $b$ from the polygon's vertices after sorting them with respect to the $y$ coordinate. This should be the easiest way to evaluate the integral. (By the way, since this is a very mathematical question, it might be better suited for math stackexchange.) –  Jul 06 '20 at 19:49
  • @Chris the Cavalieri's principle! I am not aware of this. I think I have to do some research with google. Thank you very much. – Hafid Boukhoulda Jul 06 '20 at 19:53
  • What's the polynomial degree? You can triangulate the triangle and integrate within each triangle. – lightxbulb Jul 06 '20 at 20:39
  • @lightxbulb the polynomial is of degree 3. – Hafid Boukhoulda Jul 06 '20 at 20:52
  • 1
    See this: https://computergraphics.stackexchange.com/questions/9943/how-to-compute-the-following-integral-over-a-polygon/9944#9944 It's regarding degree 2 polynomials, but the procedure is similar minus the quadrature rule which won't work anymore. – lightxbulb Jul 06 '20 at 21:34
  • Interesting approach. If the polygon is not necessarily convex, this approach may be easier to implement than what I suggested, although it does not use the special structure of the polynomial $p$ in the question (which only depends on $y$). –  Jul 07 '20 at 09:49
  • Out of curiosity, when do you need to evaluate integrals like this in computergraphics? –  Jul 07 '20 at 09:50
  • @Chris I have to confess that I don't know if the integral could be related directly to computergraphics. for me it is needed in structural engineering calculation. I am sorry if it is not very relevant to this site. – Hafid Boukhoulda Jul 07 '20 at 10:28
  • @Chris For antialiasing for example, or finite elements for solving PDEs on meshes. – lightxbulb Jul 07 '20 at 16:28
  • 1
    Yes the approach I linked is more general. If you want something specific to your problem then you have to split your integration into slabs divided by horizontal lines passing through the vertices. Let at some $y$ the left edge be between $l_1, l_2$ and the right between $r_1, r_2$. Any point on $l_1l_2$ is given by $p(\lambda) = (1-\lambda)l_1 + \lambda l_2$. You need $x$ expressed in terms of $y$ though, so $\lambda = \frac{y-l_{1,y}}{l_{2,y}- l_{1,y}}$, and you can substitute that in the expression for $x$ to get $x_l(y)$. Do the same for the right edge, then $b(y) = \|x_l(y) - x_r(y)\|$. – lightxbulb Jul 07 '20 at 16:39
  • @lightxbulb I think that is a good strategy. Is it straightforward however to identify at each step the right and the left edges? – Hafid Boukhoulda Jul 07 '20 at 17:21
  • 1
    Assuming that your polygon is convex, sort all of the vertices by $y$. Draw a line between the vertex with minimum $y$ and maximum $y$. All vertices to the left of this line will be considered on the left and all vertices to the right will be considered on the right. Start from the min $y$ vertex and walk along the left and right edges to get respectively the left and right edges. After you're done with 1 slab, move 1 vertex up (whichever's next in the ordering regardless if it is left or right). – lightxbulb Jul 07 '20 at 17:27

0 Answers0