I have a black and white picture of the world map.
I convert the pixels to a grid of binary values (0 for water, and 1 for land) indexed by coordinates (i, j). Now, say I randomly pick a point on land, and this time it's somewhere in Texas, USA. I want to know the (i, j) coordinates of all the points I can travel to without having to cross water. In this case, it would be any (i, j) in all of North and South America (minus any surrounding islands).
(The motivation behind this is that I'm trying to implement an SIR infection model in c in parallel.)
Many thanks for your help.
Edit: I'd also be interested if there are any approximate methods (I'm not overly fussed if some tiny offshore islands were included by mistake.), perhaps by a meshing method like quadtrees? Thanks again.
You're looking for a flood fill algorithm. It can be done recursively, or manually maintaining a stack, or using a queue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With