Binary Matrix Inscribed Circle

Hello!

I am trying to define a binary matrix 512x512 with an inscribed circle centered in [0,0]. Nevertheless I am getting some troubles. Below is my current code. Could someone tell me where is my mistake? When I run nothing appears in console.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <vector>

int main()
{
	int rows = 512;
	int cols = 512;
	int radius = 256;
	int m, n;
    std::vector<std::vector<float>> Circle(rows, std::vector<float>(cols, 0));
   
	for (m = rows; m <= radius; m--) {
		for (n = cols; n <= radius; n--) {

			Circle[m][n] = 1;
			std::cout << Circle[m][n]; //just to see if it is working
		}
	}
   
	return 0;

}
 
for (m = rows; m <= radius; m--) {


m starts as 512. radius is 256. m is greater than radius so the loop body never executes. Do you mean?

 
for (m = rows; m >= radius; m--) {

Thank you Seeplus! Nevertheless still getting error. I decided to change my approach:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
        int rows = 512;
	int cols = 512;
	int radius = 256;
	int m, n;
	std::vector<std::vector<float>> Circle(rows, std::vector<float>(cols, 0));
   
	for (m = 0; m < rows; m++) {
		for (n = 0; n < cols; n++) {
			if (pow(m, 2) + pow(n, 2) <= pow(radius, 2)) {

				Circle[m][n] = 1;
			}
		}
	} 


Worked, but only 1/4 of a circle was created.
Last edited on
I know that because a create a .txt

1
2
3
4
5
6
7
8
9
10
11
12
std::ofstream file("Circle.txt");
	if (!file) {
		std::cout << "\nError generating text file to store Circle.\n";
		return 1;
	}
	for (n = 0; n < cols; n++)
	{
		for (m = 0; m < rows; m++)
			file << Circle[m][n] << " ";
		file << '\n';
	}
	file.close();
SOLVED!
1
2
3
4
5
6
7
8
for (m = 0; m < rows; m++) {
		for (n = 0; n < cols; n++) {
			if (pow(m - 256, 2) + pow(n - 256, 2) <= pow(radius, 2)) {

				Circle[m][n] = 1;
			}
		}
	} 


My center was in [0][0], therefore only 1/4 was created, when I centered the circle in 256, worked!
Topic archived. No new replies allowed.