Article 51RBX Center of mass and vectorization

Center of mass and vectorization

by
John
from John D. Cook on (#51RBX)

Para Parasolian left a comment on my post about computing the area of a polygon, suggesting that I "say something similar about computing the centroid of a polygon using a similar formula." This post will do that, and at the same time discuss vectorization.

Notation

We start by listing the vertices starting anywhere and moving counterclockwise around the polygon:

listofpoints.svg

It will simplify notation below if we duplicate the last point:

centroid0.svg

The formula the centroid depends on the formula for the area, where the area of the polygon is

polygon_area.svg

Hadamard product and dot product

We can express the area formula more compactly using vector notation. This will simplify the centroid formulas as well. To do so we need to define two ways of multiplying vectors: the Hadamard product and the dot product.

The Hadamard product of two vectors is just their componentwise product. This is a common operation in R or Python, but less common in formal mathematics. The dot product is the sum of the components of the Hadamard product.

If x and y are vectors, the notation xy with no further explanation probably means the dot product of x or y if you're reading a math or physics book. In R or Python, x*y is the Hadamard product of the vectors.

Here we will use a circle a for Hadamard product and a dot for inner product.

Now let x with no subscript be the vector

centroidx.svg

and let x' be the same vector but shifted

centroidxprime.svg

We define y and y' analogously. Then the area is

polygon_vector_area.svg

Centroid formula

The formula for the centroid in summation form is

centroid_sum1.svg

where A is the area given above.

We can write this in vector form as

centroid_vector1.svg

You could evaluate v = xa y' - x'ay first. Then A is half the dot product of v with a vector of all 1's, and the centroid x and y coordinates are inner products of v with x + x' and y + y' respectively, divided by 6A.

XPfACedV0j4
External Content
Source RSS or Atom Feed
Feed Location http://feeds.feedburner.com/TheEndeavour?format=xml
Feed Title John D. Cook
Feed Link https://www.johndcook.com/blog
Reply 0 comments