Defining Triangular mesh with delaunay and inpolygon ?

1 view (last 30 days)
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 ?

Answers (1)

John D'Errico
John D'Errico on 4 Apr 2020
Edited: John D'Errico on 4 Apr 2020
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 Comment
eda yilmas
eda yilmas on 4 Apr 2020
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

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!