I have a 2-dimensional integer array (say 1000 per 1000), let me call it a matrix. Each cell in this matrix has X- and Y-coordinates (each of which is from 0 to 999 in this example). Initially, all grid cells have a value of 0. During program execution, some of the matrix cells are set to a different value <> 0.
Now I need a fast function (algorithm) that takes some X and Y values and returns the matrix value in these coordinates. However, if the matrix at the specified X / Y location is 0, then the algorithm should determine a non-zero value inside the matrix that is as close as possible to the original X / Y location.
I thought about going around the original X / Y position with an increase in the offset in each cycle of the cycle, but I'm not sure if this is really the fastest algorithm ...
Any ideas? I would prefer Java code, but any pseudo code is good too :)
Thanks in advance for your help! Regards, Matthias
source
share