Home > matGeom > geom3d > triangleArea3d.m

triangleArea3d

PURPOSE ^

TRIANGLEAREA3D Area of a 3D triangle.

SYNOPSIS ^

function area = triangleArea3d(pt1, pt2, pt3)

DESCRIPTION ^

TRIANGLEAREA3D Area of a 3D triangle.

   AREA = triangleArea3d(P1, P2, P3)
   Computes area of the 3D triangle whose vertices are given by P1, P2 and
   P3. Each vertex is either a 1-by-3 row vector, or an array with 3
   columns, each column representing coordinate of a vertex.
   The result AREA has as many rows as the number of rows of the largest
   input array.
   Compared to polygonArea3d, this function is assumed to be faster, as it
   does not requires iteration over vertices. Moreover, it can be used to
   computes the area of several triangles simultaneously.

   AREA = triangleArea3d(PTS)
   Concatenates vertex coordinates in a 3-by-3 array. Each row of the
   array contains coordinates of one vertex.


   Example
   triangleArea3d([10 10 10], [30 10 10], [10 40 10])
   ans = 
       300

   See also
   polygons3d, polygonArea3d

 ------
 Author: David Legland
 e-mail: david.legland@grignon.inra.fr
 Created: 2011-08-23,    using Matlab 7.9.0.529 (R2009b)
 Copyright 2011 INRA - Cepia Software Platform.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function area = triangleArea3d(pt1, pt2, pt3)
0002 %TRIANGLEAREA3D Area of a 3D triangle.
0003 %
0004 %   AREA = triangleArea3d(P1, P2, P3)
0005 %   Computes area of the 3D triangle whose vertices are given by P1, P2 and
0006 %   P3. Each vertex is either a 1-by-3 row vector, or an array with 3
0007 %   columns, each column representing coordinate of a vertex.
0008 %   The result AREA has as many rows as the number of rows of the largest
0009 %   input array.
0010 %   Compared to polygonArea3d, this function is assumed to be faster, as it
0011 %   does not requires iteration over vertices. Moreover, it can be used to
0012 %   computes the area of several triangles simultaneously.
0013 %
0014 %   AREA = triangleArea3d(PTS)
0015 %   Concatenates vertex coordinates in a 3-by-3 array. Each row of the
0016 %   array contains coordinates of one vertex.
0017 %
0018 %
0019 %   Example
0020 %   triangleArea3d([10 10 10], [30 10 10], [10 40 10])
0021 %   ans =
0022 %       300
0023 %
0024 %   See also
0025 %   polygons3d, polygonArea3d
0026 %
0027 % ------
0028 % Author: David Legland
0029 % e-mail: david.legland@grignon.inra.fr
0030 % Created: 2011-08-23,    using Matlab 7.9.0.529 (R2009b)
0031 % Copyright 2011 INRA - Cepia Software Platform.
0032 
0033 % if data is given as one array, split vertices
0034 if nargin == 1
0035     pt2 = pt1(2,:);
0036     pt3 = pt1(3,:);
0037     pt1 = pt1(1,:);
0038 end
0039 
0040 % compute individual vectors
0041 v12 = bsxfun(@minus, pt2, pt1);
0042 v13 = bsxfun(@minus, pt3, pt1);
0043 
0044 % compute area from cross product
0045 area = vectorNorm3d(cross(v12, v13, 2)) / 2;

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019