# The ploygon width parallel to the x axis as a function of the y ordonate?

Considering a polygon with n vertices as input.

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

• 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.) – user9485 Jul 6 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 6 at 19:53
• See this: computergraphics.stackexchange.com/questions/9943/… It's regarding degree 2 polynomials, but the procedure is similar minus the quadrature rule which won't work anymore. – lightxbulb Jul 6 at 21:34
• 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 7 at 16:39
• 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 7 at 17:27