MatlabTools(1)mesh2tri
(2010-08-04 21:25:57)
标签:
matlab
mesh2tri
杂谈
可以将结构的四边形网格转换为三角形网格。
文件下载地址:
http://www.mathworks.com/matlabcentral/fileexchange/28327-mesh2tri
但该文件中内容重复了mesh2tri函数写了两遍,可以删除重复部分。
Demo:
clear all; close all; clc;
% 1. Create mesh grid
[X,Y] = meshgrid(linspace(-10,10,25));
Z = sinc(sqrt((X/pi).^2+(Y/pi).^2));
figure('units','normalized','Position',[0 0 1 1],'Color','w');
colordef('white');
% 2. Plot the original rectangular mesh
subplot(2,2,1);
surf(X,Y,Z); hold on;
axis tight; axis square; grid on; axis off; view(3);
view(-30,70);
title('Meshgrid','FontSize',20);
%3.1 forward slash division of quadrilateral
[F,V]=mesh2tri(X,Y,Z,'f');
C=V(:,3); C=mean(C(F),2);
subplot(2,2,2);
patch('Faces',F,'Vertices',V,'FaceColor','flat','CData',C); hold
on;
axis tight; axis square; grid on; axis off; view(3);
view(-30,70);
title('Forward slash','FontSize',20);
%%3.2 back slash division of quadrilateral
[F,V]=mesh2tri(X,Y,Z,'b');
C=V(:,3); C=mean(C(F),2);
subplot(2,2,3);
%Example of using original meshgrid coordinates instead
trisurf(F,X,Y,Z);
axis tight; axis square; grid on; axis off; axis off; view(3);
view(-30,70);
title('Back slash','FontSize',20);
%%3.3 Cross division of quadrilateral
[F,V]=mesh2tri(X,Y,Z,'x');
% Replace Z-coordinates of added points by interpolated values if
desired
IND=(numel(X)+1):size(V,1);
ZI = interp2(X,Y,Z,V(IND,1),V(IND,2),'cubic');
V(IND,3)=ZI;
C=V(:,3); C=mean(C(F),2);
subplot(2,2,4);
patch('Faces',F,'Vertices',V,'FaceColor','flat','CData',C); hold
on;
axis tight; axis square; grid on; axis off; view(3);
view(-30,70);
title('Crossed','FontSize',20);
结果如下:
分享:
喜欢
0
赠金笔
加载中,请稍候......
评论加载中,请稍候...
发评论
登录名: 密码: 找回密码 注册记住登录状态
昵 称:
评论并转载此博文
发评论
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。