How to cover an irregular closed area with square pixels
2 ビュー (過去 30 日間)
古いコメントを表示
I have a set of closed curves described by the (x,y) coordinates of the approximating polygon.
My task is to cover the area enclosed by each curve with square pixel whose side is input.
No piece of the area must be left uncovered. That implies the squares covering the curve rim will lie partially inside and partially outside the curve.
In the following I describe what I have done.
- Generate a square grid of points inside or on the edge of the curve
- Generate new points lying outside the closed curve by subtracting the pixel side in the x or in the y direction
- Use Matlab function "rectangle" to build the square pixel.
- Eventually I will store to a file the coordinates of each pixel in the form X_min X_max Y_min Y_max
My problem is that some points, generated outside the closed curve, give rise to pixels that are completely outside the closed area. They do not intersect it.
I am attaching my script "Pixelize_Collimator_Aperture.m", my function "CollimatorGrid.m", and a zipped file containing the pictures of the resulting pixelized closed areas
I am pretty sure there are smarter ways to address this task. I would appreciate any suggestion and/or comment.
Thank you in advance.
Maura E.
0 件のコメント
回答 (1 件)
KSSV
2019 年 6 月 4 日
Check the code:
R = 1. ;
C = [0. 0.] ;
th = linspace(0,2*pi) ;
xc = C(1)+R*cos(th) ;
yc = C(1)+R*sin(th) ;
% Make grid
m = 50 ; n = 50 ;
xi = linspace(min(xc),max(xc),m) ;
yi = linspace(min(yc),max(yc),n) ;
[X,Y] = meshgrid(xi,yi) ;
idx = inpolygon(X(:),Y(:),xc,yc) ;
X(~idx) = NaN ;
Y(~idx) = NaN ;
figure
hold on
plot(xc,yc,'b')
plot(X,Y,'r')
plot(X',Y','r')
3 件のコメント
参考
カテゴリ
Help Center および File Exchange で Bounding Regions についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!