1

I have rectilinear polygons present, and they are surrounded by grids(grey rectangle with dots denoting center) as shown in the diagram below.

enter image description here

The grids are perfectly stacked horizontally and vertically. I have with me the coordinates of the edges (x,y) and the centre points of the grids (vectorpairint,int>>). The grids may or may not intersect with the polygon edge.

I need to find all the grid points that are immediate neighbours to that edge in the respective orientation (left,top,down,bottom).

If the red polygon were not there, I could simply find the grid point closest to the edge corners and fill the rest of the matrix, but the red box messes up the continuity. The red box is also a polygon with edge coordinates known.

I would need to do this for ~120000 edges Any performant approach to solving this?

kil47
  • 53
  • 1
  • 9
  • From what I understand, you want to find pixels marked with yellow line, however the red rectangle is a part of that white rectangle and makes it harder to find the pixels, is that right? If yes, then lets say that your polygon is defined by just an array of points [{x0,y0},{x1,y1}...] where the order matters since each line is defined by 2 neighboring points. Then all your pixels have x,y and size so then you can just devide x0/size of the pixel to find the index of that pixel and then the pixels with index-1 or +1 would be neighbouring. – Dnafiqvss May 19 '23 at 21:38

0 Answers0