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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Find a "circle" within a matrix

  1. #1
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default 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. #2
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

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

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

Similar Threads

  1. "Error cannot find symbol" "throws BadLocationException"
    By coltson in forum AWT / Java Swing
    Replies: 1
    Last Post: June 30th, 2013, 10:33 PM
  2. Replies: 2
    Last Post: June 22nd, 2013, 10:30 AM
  3. Replies: 3
    Last Post: January 22nd, 2013, 07:14 AM
  4. Find the important class in ".mse" file using Java program
    By ashwarth21 in forum Java Theory & Questions
    Replies: 3
    Last Post: March 13th, 2012, 07:43 PM
  5. Replies: 1
    Last Post: March 15th, 2010, 10:03 PM