algorithm - Find closest "true" element in 2D boolean matrix? -


i have 2d matrix boolean values, updated highly frequently. want choose 2d index {x, y} within matrix, , find nearest element "true" in table, without going through elements (the matrix massive).

for example, if have matrix:

0000100 0100000 0000100 0100001 

and choose coordinate {x1, y1} such {4, 3}, want returned location of closest "true" value, in case {5, 3}. distance between elements measured using standard pythagorean equation:

distance = sqrt(distx * distx + disty * disty) distx = x1 - x , disty = y1 - y.

i can go through elements in matrix , keep list of "true" values , select 1 shortest distance result, it's extremely inefficient. algorithm can use reduce search time?

details: matrix size 1920x1080, , around 25 queries made every frame. entire matrix updated every frame. trying maintain reasonable framerate, more 7fps enough.

if matrix being updated, there no need build auxillary structure distance transform, voronoy diagram etc.

you can execute search bfs (bread-first search) propagating query point. difference usual bfs euclidean metrics. can generate (u, v) pairs ordered (u^2+v^2) , check symmetric points shifted (+-u,+-v),(+-v,+-u) combinations (four points when u or v zero, 8 points otherwise)


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -