Green’s theorem and section properties

In the last post, I presented a simple Python module with functions for calculating section properties of polygons. Now we’ll go through the derivations of the formulas used in those functions.

The basis for all the formulas is Green’s theorem, which is usually presented something like this:

limits CPdx+Qdy=limits A(QxPy)dxdy

where P and Q are functions of x and y, A is the region over which the right integral is being evaluated, and C is the boundary of that region. The integral on the right is evaluated in accordance with the right-hand rule, i.e., counterclockwise for the usual orientation of the x and y axes.

Region and nomenclature

The section properties of interest are all area integrals. We’ll use Green’s theorem to turn them into boundary integrals and then evaluate those integrals using the coordinates of the polygon’s vertices.

Area

This is the easiest one, but instead of going through the full derivation here, I’ll refer you to this excellent StackExchange page by apnorton and just hit the highlights.

  1. The area is defined

    A=limits Adxdy

    and we’ll choose P=0 and Q=x as our Greens’ theorem functions. This gives us

    A=limits Adxdy=limits Cxdy
  2. We break the polygonal boundary into a series of straight-line segments, each of which can be parameterized this way:

    x=x i+(x i+1x i)t y=y i+(y i+1y i)t dy=(y i+1y 1)dt

    where the (x i,y i) are the coordinates of the vertices.

  3. Plugging these equations into the integral, we get

    A=12 i=0 n1(x i+1+x i)(y i+1y i)

A note on the indexing: The polygon has n vertices, which we’ll number from 0 to n1. The last segment of the boundary goes from (x n1,y n1) to (x 0,y 0). To make this work with the equation, we’ll define (x n,y n)=(x 0,y 0).

Let’s compare this with the area function in the module:

python
def area(pts):
  'Area of cross-section.'

  if pts[0] != pts[-1]:
    pts = pts + pts[:1]
  x = [ c[0] for c in pts ]
  y = [ c[1] for c in pts ]
  s = 0
  for i in range(len(pts) - 1):
    s += x[i]*y[i+1] - x[i+1]*y[i]
  return s/2

We start by checking the pts list to see if the starting and ending items match. If they don’t, we copy the starting item to the end to fit the indexing convention discussed above. We then initialize some variables and execute a loop, summing terms along the way. Rewriting the loop in mathematical terms, we get

A=12 i=0 n1x iy i+1x i+1y i

This doesn’t look like the equation derived from Green’s theorem, does it? But it’s not too hard to see that they are equivalent. Expanding out the binomial product in the earlier equation gives

x i+1y i+1x i+1y i+x iy i+1x iy i

As we loop through all the values of i from 0 to n1, the leading term of one trip through the loop will cancel the trailing term of the next trip through the loop. Here’s an example for a triangle:

(x 1y 1x 1y 0+x 0y 1x 0y 0) +(x 2y 2x 2y 1+x 1y 2x 1y 1) +(x 0y 0x 0y 2+x 2y 0x 2y 2)

After the cancellations, all that’s left are the inner terms, and that’s the formula used in the area function.

The cancellation doesn’t do much for us here, changing from two additions and one multiplication per loop to two multiplications and one addition per loop. But we’ll see this same sort of cancellation in the other section properties, and it will provide greater simplification in those.

Centroid

The centroid is essentially the average position of the area. If a sheet of material of uniform thickness and density were cut into a shape, the centroid would be the center of gravity, the balance point, of that shape. The coordinates of the centroid are defined this way:

x c=1Alimits Axdxdy y c=1Alimits Aydxdy

Let’s derive the formula for x c for a polygon; the derivation of the formula for y c will be similar.

In applying Green’s theorem, we’ll take P=0 and Q=12x 2. Therefore,

x c=1Alimits Axdxdy=limits C12x 2dy

Breaking the polygonal boundary into straight-line segments and using the same parametric equations as before, we get an integral that looks like this

0 112[(x i 2+2x i(x i+1x i)t+(x i+1x i) 2t 2](y i+1y i)dt

for each segment. This integral evaluates to

16(x i+1 2+x i+1x i+x i 2)(y i+1y i)

so our formula for the centroid is

x c=16A i=0 n1(x i+1 2+x i+1x i+x i 2)(y i+1y i)

As we found in the formula for area, the leading and trailing terms in the expansion of this product cancel out as we loop through the sum, leaving us with

x c=16A i=0 n1y ix i+1 2+y i+1x i+1x iy ix i+1x i+y i+1x i 2

This looks like a mess, but it can be factored into a more compact form:

x c=16A i=0 n1(x i+1+x i)(x iy i+1x i+1y i)

The expression for the other centroidal coordinate is as you’d expect:

y c=16A i=0 n1(y i+1+y i)(x iy i+1x i+1y i)

These are the formulas used in the centroid function.

python:
def centroid(pts):
  'Location of centroid.'

  if pts[0] != pts[-1]:
    pts = pts + pts[:1]
  x = [ c[0] for c in pts ]
  y = [ c[1] for c in pts ]
  sx = sy = 0
  a = area(pts)
  for i in range(len(pts) - 1):
    sx += (x[i] + x[i+1])*(x[i]*y[i+1] - x[i+1]*y[i])
    sy += (y[i] + y[i+1])*(x[i]*y[i+1] - x[i+1]*y[i])
  return sx/(6*a), sy/(6*a)

Moments and product of inertia

You may be familiar with moments and products of inertia from dynamics, where the terms are related to the distribution of mass in a body. The moments and product of inertia we’ll be talking about here—more properly called the second moments of area—are mathematically similar and refer to the distribution of area across a planar shape.

The moments and product of inertia that matter in beam bending are taken about the centroidal axis (i.e., a set of x and y axes with the origin at the centroid of the shape). Since we don’t know where the centroid is when we set up our coordinate system, our list of vertex points don’t work off that basis. But we can still calculate the centroidal moments and product of inertia by using these formulas:

I xx=limits A(yy c) 2dxdy I yy=limits A(xx c) 2dxdy I xy=limits A(yy c)(xx c)dxdy

We’ll concentrate on I yy; the other two will be similarly derived.

First, let’s expand the square inside the integral and see what we get:

I yy=limits Ax 2dxdy2x climits Axdxdy+x c 2limits Adxdy

The integral in the second term is Ax c and the integral in the third term is just A. Putting this together, we get1

I yy=limits Ax 2dxdyAx c 2

Since we already have formulas for x and x c, we can concentrate on the integral in the first term on the right.

Returning to Green’s theorem, we’ll use P=0 and Q=13x 3, giving us

limits Ax 2dxdy=limits C13x 3dy

Once again, we break the polygonal boundary into straight-line segments and use parametric equations to define the segments. For each segment, we’ll get the following integral:

0 113[x i 3+3x i 2(x i+1x 1)t+3x i(x i+1x 1) 2t 2+(x i+1x 1) 3t 3](y i+1y i)dt

This integral evaluates to

112[x i+1 3+x i+1 2x i+x i+1x i 2+x i 3](y i+1y i)

giving us

limits Ax 2dxdy=112 i=0 n1[x i+1 3+x i+1 2x i+x i+1x i 2+x i 3](y i+1y i)

Once again, if we expand out the product inside the sum, we’ll find that the leading and trailing terms cancel as we work through the loop. That gives us

112 i=0 n1y ix i+1 3+y i+1x i+1 2x iy ix i+1 2x i+y i+1x i+1x i 2y ix i+1x i 2+y i+1x i 3

And that long expression can be factored, leaving

limits Ax 2dxdy=112 i=0 n1(x i+1 2+x i+1x i+x i 2)(x iy i+1x i+1y i)

Similar2 derivations give us

limits Ay 2dxdy=112 i=0 n1(y i+1 2+y i+1y i+y i 2)(x iy i+1x i+1y i) limits Axydxdy=124 i=0 n1(2x i+1y i+1+x i+1y i+x iy i+1+2x iy i)(x iy i+1x i+1y i)

These formulas, and the terms accounting for the location of the centroid, are in the function inertia.

python:
def inertia(pts):
  'Moments and product of inertia about centroid.'

  if pts[0] != pts[-1]:
    pts = pts + pts[:1]
  x = [ c[0] for c in pts ]
  y = [ c[1] for c in pts ]
  sxx = syy = sxy = 0
  a = area(pts)
  cx, cy = centroid(pts)
  for i in range(len(pts) - 1):
    sxx += (y[i]**2 + y[i]*y[i+1] + y[i+1]**2)*(x[i]*y[i+1] - x[i+1]*y[i])
    syy += (x[i]**2 + x[i]*x[i+1] + x[i+1]**2)*(x[i]*y[i+1] - x[i+1]*y[i])
    sxy += (x[i]*y[i+1] + 2*x[i]*y[i] + 2*x[i+1]*y[i+1] + x[i+1]*y[i])*(x[i]*y[i+1] - x[i+1]*y[i])
  return sxx/12 - a*cy**2, syy/12 - a*cx**2, sxy/24 - a*cx*cy

This older post explains the use of the moment of inertia in beam bending, but I avoided the trickier bits associated with the product of inertia and principal axes. We’ll cover them in the next post.

Update Jan 23, 2018 12:42 PM  Thanks to Glenn Walker for finding an error in one of the formulas. They’re more annoying to me than mistakes in the text.


  1. Yes, this is the parallel axis theorem

  2. Yes, the product of inertia integral is definitely more complicated if you’re going to do the derivation by hand. So don’t do it by hand. Learn SymPy and you’ll be able to zip through it.