How to make [cx cy] the center of a user defined mesh grid of size [ix iy]
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
[EDIT: 20110629 12:13 CDT - reformat - WDR]
What I am trying is to find area of a polygon i.e. ractangle using conic sectors. For this I create a conic mask (extracted from a circle) and then rotate it over the rectangle. Let say center of the rectangle is (x, y) = [76.6, 44.1], then I would create a meshgrid with the center [cx cy] = [76.6, 44.1] and then find the conic mask with this base/origan. I have managed to make a conic mask at say [76.6, 44.1] but unfortunatly it is not the center of the mesh. So when I rotate the meshgrid using imrotate, the conic mask loses its center/base. Consequently after first iteration of theta, I am not able to caclulate the area of rectangle for the rest of conic sections. SOLUTION is that if I am able to draw cx and cy as the center of the meshgrid, then by simply imrotate my mask will rotate and I will get the area of the rectangle by rotating the mask all around 360'.
My code is as follows for creating the mask:
% --------------------------------------------------------
r = 40; % the radius of the circle from which the conic mask is to be extracted, it is large enough to accomodate the rectangle boundariesl, depends upon the size of the rectangle
cx = 76.6;
cy = 44.1;
Theta = 30; % Angle of conic section/sector
Theta1 = Theta / 2; % Get the angle divided between two linesegment slopes
ix = 3*r; iy = 3*r; % To get big enough meshgrid/image, three times the radius !! @Sean de: HERE THE PROBLEM IS!!
[X, Y] = meshgrid(-(cx - 1):(ix - cx), -(cy - 1): (iy - cy));
c_mask = ((X.^2 + Y.^2) <= r^2); % Get a circulat mask
Slope = tand(Theta1); % Create a line segment with the slope Theta1
l1 = Y - Slope * X;
L1 = (l1 < 0.0);
Slope = tand(-Theta1); % Create another line segment with slope -Theta1
l2 = Y - Slope * X;
L2 = (l2 > 0.0);
Sector = immultiply(L1,L2); % Get the sector common between two line segments
c_mask = immultiply(Sector, c_mask); % Get the conic section of the circular mask at the defined x-y
% DISPLAY MASK
figure ,
subplot(311), imshow(L1), title('Line 1')
axis on, hold on
subplot(312), imshow(L2), title('Line 2')
axis on, hold on
subplot(313), imshow(Sector), title('Conic sector')
axis on, hold on
h = imcontour( Sector, 1, 'r');
9 Kommentare
Sean de Wolski
am 30 Jun. 2011
I don't see how a conic sector would calculate the area of the blob in the first image... You can privately email me the data you have if you want. This may be a thread better posed for the newsreader (http://www.mathworks.com/matlabcentral/newsreader/). There are more computational geometry pros there.
Antworten (1)
Paulo Silva
am 29 Jun. 2011
12 Kommentare
Paulo Silva
am 29 Jun. 2011
Faraz please edit your first question and add all the details, that way Sean and others can help you better.
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!