### 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.

 ``12345678910111213141516171819202122`` ``````#include #include int main() { int rows = 512; int cols = 512; int radius = 256; int m, n; std::vector> Circle(rows, std::vector(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:
 ``1234567891011121314`` `````` int rows = 512; int cols = 512; int radius = 256; int m, n; std::vector> Circle(rows, std::vector(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

 ``123456789101112`` ``````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!
 ``12345678`` ``````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 , therefore only 1/4 was created, when I centered the circle in 256, worked!
Topic archived. No new replies allowed.