I was trying to expand or shrink the 2d object up to K. Let's say I've a co-ordinate system like { {5,0}, {0,0}, {0,-5}, {5,-5}, {5,-10}, {0,-10} } (yellow marker shape) and I want to offset every position K = 1. The resultant shape would look something like this
As my initial approach was to find the center of the shape and increase each coordinate according to the center, the source is here. But it seems like it only works on a closed symmetric shape like squares and for asymmetric shapes or open shapes, it doesn't work.
My code is given below
void myFun() {
std::vector<std::pair<double, double>> co, CO;
co = { { {5,0}, {0,0}, {0,-5}, {5,-5}, {5,-10}, {0,-10} } };
double x = 0, y = 0;
double n = co.size();
for (auto it : co) {
x += it.first; y += it.second;
}
std::pair<double, double> o = { x / n, y / n };
int K = 1;
for (auto it : co) {
std::pair<double, double> inc = { (it.first - o.first) * K, (it.second - o.second) * K };
CO.push_back({ o.first - inc.first, o.second - inc.second });
}
reverse(CO.begin(), CO.end());
for (auto it: CO) {}
}
The output co-ordinate shape is
How can I improve my approach and solve this issue? Thank you.

