Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Find a "circle" within a matrix

1. ## Find a "circle" within a matrix

Hi there.

My problem is, that I want to find a "circle" within a matrix, but I just cant wrap my head around it at the moment. It seems like I am having a blockade in my head.
Lets assume we have a big matrix filled with integer numbers, like this:
```     0) 1) 2) 3) 4) 5) 6) 7)
0) [ 0, 0, 0, 0, 0, 0, 0, 0 ]
1) [ 0, 0, 0, 0, 0, 0, 0, 0 ]
2) [ 0, 0, 0, 0, 0, 0, 0, 0 ]
3) [ 0, 0, 0, 0, 0, 0, 0, 0 ]
4) [ 0, 0, 0, 0, 0, 0, 0, 0 ]
5) [ 0, 0, 0, 0, 0, 0, 0, 0 ]
6) [ 0, 0, 0, 0, 0, 0, 0, 0 ]```
And I specify one of the cells of the matrix and the size of the circle:
`matrix.doCircle(column = 3, row = 4, radius = 2.5);`
The resulting matrix should look like this:
```     0) 1) 2) 3) 4) 5) 6) 7)
0) [ 0, 0, 0, 0, 0, 0, 0, 0 ]
1) [ 0, 0, 0, 1, 1, 1, 0, 0 ]
2) [ 0, 0, 1, 1, 1, 1, 1, 0 ]
3) [ 0, 0, 1, 1, 1, 1, 1, 0 ]
4) [ 0, 0, 1, 1, 1, 1, 1, 0 ]
5) [ 0, 0, 0, 1, 1, 1, 0, 0 ]
6) [ 0, 0, 0, 0, 0, 0, 0, 0 ]```
So a circle centered at (3, 4) with the radius 2.5 has been filled with 1's in that matrix.
The circle should be as smooth as possible, and the matrices and radii could get very big.

Does anybody know a good algorithm which would solve this problem in a somewhat effective way?

Thank you very much.

2. ## Re: Find a "circle" within a matrix

Hi Cornix

Give this a view - I had quite a long look at various information
and found this to be the most helpful.

Midpoint circle algorithm - Wikipedia, the free encyclopedia

The sample code they give is written in C#, but is very much like Java syntax
as I am sure you know. If it is not quite what you are after, the programming
site "stack overflow" has a few snippets of this type of algorithm too.