There is a grid which has been overlaid on top of a polygon. To make the discussion concrete, assume the following picture:
I had the yellow polygon and I want to overlay a grid as shown in the image. I wish to color the grid cells based on certain rules. They are not as simple as coloring the intersecting cells red and rest green. I want to preform a conditional check on each grid cell and then color them based on the result. I am at a loss to think how to represent the grid cells and then proceed with my conditional checks on them. This is my first issue. This is more of a data structure question.
Next if I know which certain cells to color orange, how do I do it? This is a graphics question.
I could figure out how to for 1x1
grid cells basically the points like this:
figure
hold on
roi=[264.418629550321 234.728971962617;207.673447537473 220.710280373832;206.60278372591 78.1869158878505;75.9817987152034 66.5046728971964;58.8511777301927 447.345794392523;201.249464668094 454.355140186916;294.39721627409 380.757009345795;447.502141327623 430.990654205608;476.410064239829 262.766355140187;464.632762312634 213.700934579439;428.230192719486 145.943925233645;365.061027837259 134.261682242991;307.245182012848 152.953271028038;285.831905781585 193.841121495327];
axis([0 500 0 500])
axis equal
view([0 -90])
X=roi(:,1);
Y=roi(:,2);
[a b] = meshgrid(1:500);
inPoly1 = inpolygon(a,b,X,Y);
imagesc(inPoly1);
line(X, Y,'Color','r');
for k = 1:25:500
x = [1 500];
y = [k k];
plot(x,y,'Color','w','LineStyle','-');
plot(x,y,'Color','k','LineStyle',':');
end
for k = 1:25:500
x = [k k];
y = [1 500];
plot(x,y,'Color','w','LineStyle','-');
plot(x,y,'Color','k','LineStyle',':');
end
This code snippet can also be used to produce above image. But this is not helpful. I want to be able to work with general nxn
grid cells in this same way.
I had a naïve idea that I will form a Matlab-cell of all the quadrilaterals that are the grid cells and then do my conditional check over them and color them just as polygons using fill command. Is there a better, easier way so that I have to reinvent the wheel as less as possible? If your advice is that I should go ahead with this idea, then can you suggest a way to form the Matlab-cell of all these quadrilaterals in a smart way?
I saw here but this uses Mapping toolbox which I don't have. So if someone can suggest within the realm of basic matlab toolboxes, it will be highly appreciated. Else please suggest python solutions. If it is difficult to provide code snippets, algorithmic advice would also be helpful.