% MotionGenesis file: TetrahedronInertiaAboutVertex0.r
% Copyright (c) 2025-2026 Motion Genesis LLC.  All rights reserved.
%----------------------------------------------------------------------------
%TetrahedronInertiaAboutVertex0
%TetrahedronInertiaAboutVertex0
%
% Purpose:  Calculates a tetrahedron's inertia dyadic about its 0th vertex using
%           position vectors from a point P to various tetrahedron vertices.
%
%Syntax 1:  TetrahedronInertiaAboutVertex0( mass, p0>, p1>, p2>, p3> ) 
%Syntax 2:  TetrahedronInertiaAboutVertex0( mass, p1>, p2>, p3> )
%
%   Input:  mass -- The tetrahedron's mass. 
%           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.
%           p3> -- position vector from point P to vertex 3.
%
%Output 1:  The inertia dyadic about vertex 0.
%Output 2:  The inertia dyadic about vertex 0 which is point P.
%
%  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# < 4 ) { echo("\n\a\kError: The command TetrahedronInertiaAboutVertex0 has too few arguments.") }
ELSEIF( #NUM_ARGS# > 5 ) { echo("\n\a\kError: The command TetrahedronInertiaAboutVertex0 has too many arguments.") }
ELSEIF( #NUM_ARGS# == 5 ) 
{ 
   TetrahedronInertiaAboutVertex0(#1#, #3# - #2#, #4# - #2#, #5# - #2#) 
}
ELSE
{
  (#1#)/6 * (1>> * (Dot(#2#, #2#) + Dot(#3#, #3#) + Dot(#2#, #3#)) &
     - ((#2#)*(#2#) + (#2#)*(#3#)/2 + (#3#)*(#2#)/2 + (#3#)*(#3#)) )
}
% end of file
