<p>Considering a polygon with n vertices as input.</p>
<p><a href="https://i.sstatic.net/bWunO.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/bWunO.png" alt="enter image description here" /></a></p>
<p>I need to calculate the integral of the form
\[\int_A p(y) dA \] where <span class="math-container">$p(y)$</span> is a piecewise polynomial function of <span class="math-container">$y$</span>.</p>
<p>May be if I could find  the expression <span class="math-container">$b(y)$</span> then the integral can be calculated by:
<span class="math-container">$$\int_{0}^{y_\max} p(y) b(y) dy $$</span></p>
<p>The question is : &quot;is there a straightforward method to find <span class="math-container">$b(y)$</span> given the coordinates of the polygon vertices? Or is there a simpler manner to calculate the integral above?&quot;</p>

CC BY-SA 4.0
2020-07-06T19:53:13.090Z
@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
CC BY-SA 4.0
2020-07-06T20:39:04.673Z
What's the polynomial degree? You can triangulate the triangle and integrate within each triangle.
lightxbulb
CC BY-SA 4.0
2020-07-06T20:52:00.083Z
@lightxbulb the polynomial is of degree 3.
Hafid Boukhoulda
CC BY-SA 4.0
2020-07-06T21:34:13.650Z
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
CC BY-SA 4.0
2020-07-07T10:28:15.857Z
@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
CC BY-SA 4.0
2020-07-07T16:28:26.767Z
@Chris For antialiasing for example, or finite elements for solving PDEs on meshes.
lightxbulb
CC BY-SA 4.0
2020-07-07T16:39:41.943Z
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
CC BY-SA 4.0
2020-07-07T17:21:26.580Z
@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
CC BY-SA 4.0
2020-07-07T17:27:41.057Z
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
<geometry><polygon><integral>
The ploygon width parallel to the x axis as a function of the y ordonate?
Hafid Boukhoulda
# The ploygon width parallel to the x axis as a function of the y ordonate?

(Asked by: username_0 on 2020-07-06)

Considering a polygon with n vertices as input.

[![enter image description here](https://i.sstatic.net/bWunO.png)](https://i.sstatic.net/bWunO.png)

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?"

**Tags:** geometry, polygon, integral

> **Comments:**
> **username_0**: @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.  
> **username_1**: What's the polynomial degree? You can triangulate the triangle and integrate within each triangle.  
> **username_0**: @username_1 the polynomial is of degree 3.  
> **username_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.  
> **username_0**: @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.  
> **username_1**: @Chris For antialiasing for example, or finite elements for solving PDEs on meshes.  
> **username_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)\|$.  
> **username_0**: @username_1 I think that is a good  strategy. Is it straightforward however to identify at each step the right and the left edges?  
> **username_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).  

---

## 0 answers

