How can I merge two surfaces?
22 次查看(过去 30 天)
显示 更早的评论
Hi to everyone,
I have to surfaces (created with hold on/off), but I need them to as one surface, to merge them and than that surface combine with one ellipse to become one ruled surface.
I hope my question is clear.. how can I merge two surface, create them as one without using hold on/off?
Thank you
0 个评论
回答(2 个)
Thomas Seers
2015-4-25
Assuming you have two sets of vertex lists, pointsA & pointsB, and two sets of face lists, facesA and facesB, you probably want to stack both sets and update the lower face list. The solution is shown in the demo program below:
% create paired surfaces
gridx = repmat(linspace(-1,1,5),5,1);
gridy = repmat(transpose(linspace(-1,1,5)),1,5);
pointsA = [reshape(gridx,5^2,1) reshape(gridy,5^2,1) zeros(5^2,1)+rand(25,1)/10];
pointsB = [reshape(gridx,5^2,1) reshape(gridy,5^2,1) ones(5^2,1)+rand(25,1)/10];
% triangulate
facesA = delaunay(pointsA(:,1), pointsA(:,2));
facesB = delaunay(pointsB(:,1), pointsB(:,2));
% % visualize
trisurf(facesA, pointsA(:,1), pointsA(:,2), pointsA(:,3));
colormap jet % Default color map.
set(gca, 'Position', [0 0 1 1]); % Fill the figure window.
axis equal vis3d; % Set aspect ratio.
shading interp; % Interpolate color across faces.
camlight left; % Add a light over to the left somewhere.
lighting gouraud; % Use decent lighting.
hold on;
% visualize
trisurf(facesB, pointsB(:,1), pointsB(:,2), pointsB(:,3));
colormap jet % Default color map.
set(gca, 'Position', [0 0 1 1]); % Fill the figure window.
axis equal vis3d; % Set aspect ratio.
shading interp; % Interpolate color across faces.
camlight left; % Add a light over to the left somewhere.
lighting gouraud; % Use decent lighting.
pause(2);
% stack the vertex lists
points = vertcat(pointsA, pointsB);
% update the face list
faceUpdate = facesB+max(max(facesA));
faces = vertcat(facesA,faceUpdate);
close(gcf);
% visualize merged surfaces
trisurf(faces, points(:,1), points(:,2), points(:,3));
colormap jet % Default color map.
set(gca, 'Position', [0 0 1 1]); % Fill the figure window.
axis equal vis3d; % Set aspect ratio.
shading interp; % Interpolate color across faces.
camlight left; % Add a light over to the left somewhere.
lighting gouraud; % Use decent lighting.
Hope this helps
Thomas
0 个评论
Besim Helic
2015-4-26
2 个评论
Thomas Seers
2015-4-26
circular segment and a line indicates 2D geometry: I take it that you mean a semi cylinder and a planar surface. Are you are calling meshgrid?
Thomas Seers
2015-4-26
BTW you should place comments in the comment box or update your original answer.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!