Defining Triangular mesh with delaunay and inpolygon ?

1 回表示 (過去 30 日間)
eda yilmas
eda yilmas 2020 年 4 月 4 日
コメント済み: eda yilmas 2020 年 4 月 4 日
Hello everyone;
I want to draw my shape functions in 3D over triangular domain:
S1=-1+2x+2y, shape functions contains x and y values.
I can triangulize the mesh (obtain 2 triangle)
[x,y] = meshgrid(0:1,0:1);
tri = delaunay(x,y);
trisurf(tri,x,y,zeros(size(x)))
But I want to only use points from one triangle.
I tried to use inpolygon but I dont understand how it works ?

回答 (1 件)

John D'Errico
John D'Errico 2020 年 4 月 4 日
編集済み: John D'Errico 2020 年 4 月 4 日
Easy peasy. And there is no need to bother with inpolygon here.
[x,y] = meshgrid(0:.1:1);
xy = [x(:),y(:)];
xy(xy(:,1) > xy(:,2),:) = [];
tri = delaunayn(xy);
zfun = @(x,y) 1 + 2*x + 2*y;
z = zfun(xy(:,1),xy(:,2));
H = trisurf(tri,xy(:,1),xy(:,2),z);
H.EdgeColor = 'none';
H.FaceColor = 'interp';
xlabel X
ylabel Y
grid on
box on
Note that my use of a finer mesh allows you to have had a more complicated surface, with some curvature in there, even though the function you indicated was purely planar.
As necessary IF that shape function is nonlinear, make sure you know how to use the .* and .^ and ./ operators to allow for vectorized evaluation in the function.
  1 件のコメント
eda yilmas
eda yilmas 2020 年 4 月 4 日
Thank you so much :)
I try to understand what u did in your code step by step, I only change the following step
xy(xy(:,1) > xy(:,2),:) = [];
to define another triangular mesh :)
Have a good day

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by