for loop - plot multiple 3D rectangles in matlab -
this question exact duplicate of:
i have array of data points of size 400x3 (400 points x,y,z coordinates). each group of 4 consecutive points represent corners of rectangle, there 100 rectangles (finite planes).
i plot 100 rectangles in 3d, new matlab.
so far able plot single rectangle:
% sample rectangle pointb=[16.1445 20.0025 1.64238]; pointc=[21.7378 29.1242 1.64238]; pointd=[30.8595 23.5309 -1.64238]; pointe=[25.2662 14.4092 -1.64238]; % plot in 3d points=[pointb' pointc' pointd' pointe']; fill3(points(1,:),points(2,:),points(3,:),'r') grid on alpha(0.3)
so how repeat remaining rectangles.. help!
this should it...
% load sample points pointb=[16.1445 20.0025 1.64238]; pointc=[21.7378 29.1242 1.64238]; pointd=[30.8595 23.5309 -1.64238]; pointe=[25.2662 14.4092 -1.64238]; % dimensions of points bcde(4) x xyz(3) x shapes(1) points = [pointb; pointc; pointd; pointe]; size(points) % permute dimensions fill3 bcde(4) x shapes(1) x xyz(3) points = permute(points, [1 3 2]); size(points) % make simulated rectangles (you load these file) % add xyz, making copies along 2nd (shapes) dimension % offset 1 x shapes(11) x xyz(3) offset = permute([0:10:100; 0:10:100; 0:1:10], [3 2 1]); % dimensions of points bcde(4) x shapes(11) x xyz(3) points = bsxfun(@plus, points, offset); size(points) % extract x,y,z, each bcde(4) x shapes(11) x = points(:,:,1); y = points(:,:,2); z = points(:,:,3); % plot fill3(x, y, z, 'r'); grid on; alpha(0.3);
Comments
Post a Comment