How to create nested polygon

Nope! There’s no need to do any sort of shifting at all!

Consider a simple case: Your polygon has four points. So then the shape made by drawing lines between those points has… four sides. That means there are going to be four midpoints to use for the next iteration! Notice how the number of points/lines/midpoints is always the same and unchanging?

This solves another question: How big do your nextX and nextY arrays need to be? They need to be the same length as your px and py arrays!