我有一个大小为400x3的数据点数组(400点,x,y,z坐标)。 每组4个连续点代表矩形的角, 所以有100个矩形(有限平面)。
我想在3D中绘制所有100个矩形,但我对matlab很新。
到目前为止,我可以绘制一个矩形:
% A 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)
那么如何为剩余的矩形重复此操作..帮助!
答案 0 :(得分:0)
应该这样做......
% 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];
% The dimensions of points are now BCDE(4) x XYZ(3) x shapes(1)
points = [pointB; pointC; pointD; pointE];
size(points)
% Permute the dimensions for fill3 BCDE(4) x shapes(1) x XYZ(3)
points = permute(points, [1 3 2]);
size(points)
% Make some simulated rectangles (you would load these from a file)
% We will add to XYZ, making copies along the 2nd (shapes) dimension
% offset is 1 x shapes(11) x XYZ(3)
offset = permute([0:10:100; 0:10:100; 0:1:10], [3 2 1]);
% The dimensions of points are now BCDE(4) x shapes(11) x XYZ(3)
points = bsxfun(@plus, points, offset);
size(points)
% Extract X,Y,Z, so each is 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);