% MotionGenesis file: TriangleArea.r
% Copyright (c) 2025-2026 Motion Genesis LLC.  All rights reserved.
%----------------------------------------------------------------------------
%TriangleArea
%TriangleArea
%
% Purpose:  Calculates a triangle's area (as a vector) using position
%           vectors from a point P to various vertices on the triangle.
%
%Syntax 1:  TriangleArea( p0>, p1>, p2> )
%Syntax 2:  TriangleArea( p1>, p2> )
%
%   Input:  p0> -- position vector from point P to vertex 0.
%           p1> -- position vector from point P to vertex 1.
%           p2> -- position vector from point P to vertex 2.
%
%Output 1:  The triangle's vector area (having magnitude and sense).
%Output 2:  The triangle's vector area (assumes point P is vertex 0).
%
%  Remark:  One way to calculate the triangle's mass is: 
%           triangleMass = rho * Dot( TriangleArea(...), unitVector> )
%	    where rho is the triangle density per unit area and
%           unitVector> is perpendicular to the triangle (its sense of
%           direction can produce a negative or positive mass).
%
% Related:  SetMass          GetMass         SetInertia
%           GetCmPosition    GetCmVelocity   GetCmAcceleration
%           GetInertiaDyadic  GetInertiaMatrix  GetMomentOfInertia
%           GetProductOfInertia  GetRadiusOfGyration  GetInertiaVector
%	    TriangleArea       TriangleCMPosition     TriangleInertiaAboutVertex0
%	    TetrahedronVolume  TetrahedronCMPosition  TetrahedronInertiaAboutVertex0
%----------------------------------------------------------------------------
IF(     #NUM_ARGS# < 2 )  { echo("\n\a\kError: The command TriangleArea has too few arguments.") }
ELSEIF( #NUM_ARGS# > 3 )  { echo("\n\a\kError: The command TriangleArea has too many arguments.") }
ELSEIF( #NUM_ARGS# == 3 ) 
{ 
   (Cross(#2#, #3#) + Cross(#1#, #2# - #3#) )/2
%  TriangleArea(#2# - #1#, #3# - #1#)  % Less efficient version.
}
ELSE 
{ 
   Cross(#1#, #2#)/2 
}
% end of file
