I am trying to fill a circle with this algorithm. fill_circle I would like to save the output (x,y) coordinates. Can anyone help me to save the vector of struct? Thank you!
struct point
{
int x = 0;
int y = 0;
};
void fill_circle(point const& center, int radius, std::vector<point>& points)
{
int sqr_rad = radius * radius;
for (int px = center.x - radius; px <= center.x + radius; px++)
{
for (int py = center.y - radius; py <= center.y + radius; py++)
{
int dx = center.x - px, dy = center.y - py;
if (dx * dx + dy * dy <= sqr_rad)
points.push_back({px, py});
}
}
}
std::string input_v, input_h; // (v, h) input string
size_t tdata_v, tdata_h; // (v, h) of selected pixel
struct point Center;
std::vector<point> pixels;
std::cout << "Please enter (v) of pixel: ";
getline (std::cin, input_v);
std::stringstream(input_v) >> tdata_v;
Center.x = static_cast<int>(tdata_v);
std::cout << "Please enter (h) of pixel: ";
getline (std::cin, input_h);
std::stringstream(input_h) >> tdata_h;
Center.y = static_cast<int>(tdata_h);
fill_circle(Center, 50, pixels);
sprintf(circlename, "%scircle_v%04zu_h%04zu.txt", writepath.c_str(), tdata_v, tdata_h); // The path to the file to be written
How can I write all the pixels.x and pixels.y to the circle_v_h.txt in the format?
pixels_x, pixels_y; ...
Thanks!