Given a grid map where each cell can be described by a pair (x, y), and a vector of such cells, how can I (nicely) check if the cells in that vector form a ‘tunnel’, ie. they are all lined up either vertically or horizontally? But what if I only want to see if most of them are lined up (and not all)?
All are lines up Most are lined up Not lined up
C C C C
C C C C C C C C C C C C C C C C C C C C
C C C C C
C C
You could calculate the standard deviation of both the X and Y coordinates. The more ‘tunnelled’ your cells are, the lower the std deviation will be for either X or Y.
For example, in Python:
It’s up to you to determine what the value of STD_DEVIATION_THRESHOLD should be.