Answer the question
In order to leave comments, you need to log in
Cut off all intersecting circles. The most trivial task, but misunderstandings arise during implementation.
Most likely this is due to an incomplete understanding (by me) of the specifics of the JAVA language.
In general: there is a two-dimensional array array[][], where each coordinate corresponds to either zero or non-zero. Not zero means at this point the center of the circle, and the radius is set from the outside and it is constant throughout the cycle. The value of the array element means the approximate probability that the center of the circle should actually be at this point. There is a certain parameter ( kriteria
) that cuts off all unlikely options.
There are many circles whose centers are very close to each other, and there are also circles that intersect. This is harmful, because. the array data is used for subsequent statistical processing.
Actually how I do it:
- // Analysis of the original array.
- for ( int x1 = 0 ; x1 < width ; x1 ++ ) {
- for ( int y1 = 0 ; y1 < height ; y1 ++ ) {
- // If the counter is less than the criterion, then reset it to hell.
- if ( array [ x1 ] [ y1 ] < kriteria ) {
- array [ x1 ] [ y1 ] = 0 ;
- } else { // If not, continue the comparison.
- for ( int x2 = x1 + 1 ; x2 < width ; x2 ++ ) {
- for ( int y2 = y1 + 1 ; y2 < height ; y2 ++ ) {
- // If the counter is less than the criterion, then reset it to hell.
- if ( array [ x2 ] [ y2 ] < kriteria ) {
- array [ x2 ] [ y2 ] = 0 ;
- } else { // If not, continue the comparison.
- // It's time to calculate the distance between the circles.
- long rasst = Math . round ( Math . sqrt ( Math . pow ( y2 - y1, 2 ) + Math . pow ( x2 - x1, 2 ) ) ) ;
- if ( rasst < rasstKriteria ) {
- array [ x2 ] [ y2 ] = array [ x1 ] [ y1 ] + array [ x2 ] [ y2 ] ;
- array [ x1 ] [ y1 ] = 0 ;
- }
- }
- }
- }
- }
- }
- }
Answer the question
In order to leave comments, you need to log in
It seems to me that the problem may be due to the fact that the inner loop (c x2 and y2) goes over too limited an area - over a rectangle from (x1, y1) to (width, height), although it should go through all the elements of the rectangle ( x1 + 1, 0) - (width, height) and element by element (x1, y1 +1) - (x1, height).
In your case, there will never be a comparison of such points, for example, as (x1, y1) and (x1 + 1, y1 -1), because the second is not included in the inner loop.
I have another idea for you.
Why are you using such a huge nested second loop? Indeed, for the point (0,0), the second cycle will run through essentially the entire array (how many do you have there - 3000x2000?). It would be possible to run only [x1,x1+rasstKriteria],[y1,y1+rasstKriteria]. I think it's more efficient.
Sorry for being off topic, but I just couldn't get past the rasst and rasstKriteria variables silently >.<
why didn't you name the width and height variables shirin and visot respectively?
It doesn't seem to me that the question here is really only a misunderstanding of the specifics of Java. A few points stand out to me:
- I would do the zeroing "to hell" in one place with a full double cycle at the beginning (less side effects to track).
- Math.round rounding confuses. Is this exactly what you need? Simply, in principle, this can be the reason for the loss of several options.
- well, check if you forgot to take into account the doubling of the radius in rasstKriteria.
In general, it is really difficult to make assumptions without seeing at least some example.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question