Using patch to create 3D shape from an extruded polyshape

6 ビュー (過去 30 日間)
Abel Matser
Abel Matser 2020 年 9 月 24 日
回答済み: Abel Matser 2020 年 9 月 25 日
Dear Walter, I am looking to a similar solution, but the code you provided did not directly work for me. Matlab R2019a throws two errors. I'm using the following code:
% Example with data
shape = polyshape([0 0 1 1 0.5],[1 0 0 1 1.5]);
x = shape.Vertices(:,1);
y = shape.Vertices(:,2);
num_x = numel(x);
ub = 0.7;
lb = 0.1;
z = lb * ones(num_x,1);
x2 = x;
y2 = y;
z2 = ub * ones(num_x,1);
verts = [x(:), y(:), z(:); x2(:), y2(:), z2(:)];
numvert = length(x);
% Comment to create picture
faces(1,:) = 1:numvert; %draw first polygon
faces(2,:) = numvert+1:2*numvert; %draw second polygon
vL = (1 : numvert - 1) .';
faces(2+vL,1:4) = [vL, vL + 1, numvert + 1 + vL, numvert + vL];
faces(2+numvert,1:4) = [numvert, 1, 2*numvert, numvert+1];
% Uncomment to create picture
% faces = faces(3:end,:);
figure
ax = axes('XLim',[-3 3],'YLim',[-3 3],'ZLim',[-2 2]);
view(3)
grid on
alpha = 0.5;
p = patch('Faces',faces,'Vertices',verts,'FaceColor','red')
I'm trying to create an extrusion of a house shape in this example, which uses 5 points. The first error is caused because my shape has 5 points instead of 4.
% Unable to perform assignment because the size of the left side is 1-by-4
% and the size of the right side is 1-by-5.
% Error in polyshape2solid (line 74)
% faces(1,:) = 1:numvert; %draw first polygon
The second error is when I leave the declaration of faces(1:2,:) empty
% Error using patch
% Value must be of numeric type and greater than 1
Lastly, I deleted the first two rows faces(1:2,:). This results in an incomplete patch, see the attached picture.

回答 (1 件)

Abel Matser
Abel Matser 2020 年 9 月 25 日
I got the answer from another post on the forum. Link

カテゴリ

Help Center および File ExchangeElementary Polygons についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by