forked from rajexplo/DG_Matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrgArea.m
24 lines (21 loc) · 796 Bytes
/
trgArea.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function [a] = trgArea(p, t)
% Computes the area of all triangles in a triangular mesh.
% When ( meshData.elementType == 'triangular' )
% p, t should be meshData.P, meshData.T (see meshInfo.m for details).
%
% It returns a row vector A of dimension = meshData.nT,
% which contains the areas of each triangle.
% indices of points
p1Ind = t(1,:);
p2Ind = t(2,:);
p3Ind = t(3,:);
% x and y components of edge12 and edge13
% Example of edge naming convention:
% edge23x means x component of edge from p2 to p3
% edge32y means y component of edge from p3 to p2
edge12x = p(1,p2Ind) - p(1,p1Ind);
edge12y = p(2,p2Ind) - p(2,p1Ind);
edge13x = p(1,p3Ind) - p(1,p1Ind);
edge13y = p(2,p3Ind) - p(2,p1Ind);
% area
a = (1/2)*(edge12x.*edge13y - edge12y.*edge13x);