I am working with a 2D mesh generated by Gmsh and here I'd like to compute the area of the triangles of in my mesh. What I don't understand is how can I find the coordinates of a given triangle?
In my .m file, I have: msh.nbNod, msh.POS, msh.Max and msh.MIN, msh.LINES, msh.TRIANGLES and msh.PNT.
I think I should somehow use msh.TRIANGLES but I don't get what the numbers listed refer to. If needed, I can post my .m file. Thanks for the help.

댓글 수: 3

Turlough Hughes
Turlough Hughes 2021년 11월 3일
편집: Turlough Hughes 2021년 11월 3일
Can you attach a msh.mat?
Done!
Florian Spicher
Florian Spicher 2021년 11월 3일
편집: Florian Spicher 2021년 11월 3일
Or maybe I misunderstood what you meant since you edited several times your comment, sorry.

댓글을 달려면 로그인하십시오.

 채택된 답변

Dave B
Dave B 2021년 11월 3일
편집: Dave B 2021년 11월 3일
It looks to me like msh.TRIANGLES is referring to indices in msh.POS, which like a reasonable way to describe a mesh.
I'd grab the co-ordinates of a triangle's vertices like this:
squareRing;
triangle_ind=500;
msh.POS(msh.TRIANGLES(triangle_ind,1:3)',:)
ans = 3×3
-1.1902 -0.8650 0 -1.1905 -1.0510 0 -1.3512 -0.9948 0
(Here each row is a vertex, and the columns are x,y,z)
I say it's reasonable, because this is similar to what patch would use (and because max(msh.TRIANGLES(:))==size(msh.POS,1)).
patch('Faces',msh.TRIANGLES(:,1:3),'Vertices',msh.POS,'FaceColor','none','EdgeColor','r')
Note that in the data file you provided, the third column of msh.POS is all zeros, which I assume means that they are all in a 2-D plane.

댓글 수: 5

That's the case, it's in the Oxy-plane. Thank you very much for the help :)
I'm not quite sure to fully understand why you set triangle_ind to be equal to 500 though.
Oh I just picked some particular triangle off the top of my head because you said 'given triangle'...
You can get all the triangles with (I dropped the z-coord because they're all 0):
alltri=msh.POS(msh.TRIANGLES(:,1:3)',1:2);
Now the first 3 rows of alltri are the first triangle, rows 4-6 are the second triangle, etc.
You could reshape that into a 3-D matrix with some gymnastics (maybe there's an easier incantation of reshape/permute, this is what I came up with):
alltri3=permute(reshape(alltri',2,3,[]), [2 1 3]);
So now alltri3(:,:,1) is the first triangle, alltri3(:,:,2) is the second triangle, etc.
I think that all of the areas would be:
ar=squeeze(polyarea(alltri3(:,1,:),alltri3(:,2,:)));
Aha! Now it’s 100% clear! Well, thank you very much :) you really helped
Hi
How did you get the xy for each triangle in the first place?
Cheers
Camille

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2021년 11월 3일

댓글:

2023년 2월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by