Shrink polygon using corner coordinates

I'm trying to figure out how to shrink a polygon using only the coordinates of its corners. For example, if I have the following shape with corners at [(0, 0), (0, 100), (20, 100), (30, 60), (40, 100), (60, 100), (60, 0), (40, 10), (40, 40), (20, 40), (20, 10)] so the shape looks like this:

And I want to find the corner coordinates for if I shrink this polygon by some width and height factor. For example, If I want to shrink its width by 10% and height by 20% then this could be shown as something like this:

I originally asked this on StackOverflow, and it was suggested that this can be easily solved with analytic geometry. I don't know any analytic geometry, so I'm not sure where to start with solving this problem. Is there a straightforward way to do this?

• Where do you want the reduced figure to end up? It looks like you’d like some “center” point to remain fixed. – amd Mar 29 '18 at 20:48

It's clear that if we figure out where each vertex goes, we should be able to retrace the structure.

To begin, let's compute the centers of mass of the left polygonal block, pretending there is an edge $(20,100) \to (20, 40)$ and the right polygonal block, pretending there is an edge $(40,100) \to (40, 40)$, and let's also compute the center of mass of the middle structure. Call these centers of mass $L, R,$ and $C$, respectively.

The vertices on the outer edges $x=0$ would shrink towards $L$, and vertices at $x=60$, -- towards $R$. Perhaps the middle vertices can shrink towards the center of mass of the entire structure, but that would mean the vertex at $(20, 100)$ will shift right, not left as you have drawn it. Not sure if this is the desired behavior or not.

If not, you can move the points at $x=20$ towards $L$ and and $x=40$ towards $R$.

In either case, you will shrink $(30,60)$ towards $C$.

We now reduced this to shrinking a convex polygon to it's center of mass, please let me know if you need any help with that problem in the comments.

The center of mass problematic might obscure the thing. So set this point out of scope here.

The remainder is straight forward. If x is the width coordinate and y is the height coordinate, and you want to have a width factor of W % and a height factor of H %, then you just get the new coordinates (up to some overall shift) as

$x_{new} = x_{old}\cdot\frac{W}{100}$
$y_{new} = y_{old}\cdot\frac{H}{100}$

--- rk

This problem can be very easily handled in the complex plane, if that is available to you. First, you must move the origin to the center of the image, as noted in another answer. Call this $z$. Now, to construct a scaled figure, which scales as $a$ and $b$ in the $x$ and $y$ directions, respectively, we get the result

$$w=a\cdot \Re \{z\}+i~b\cdot \Im \{z\}$$

The figure below shows the results for the original and scaled images as per the parameters you specified.