2 // ********************************************************************
 
    3 // * This Software is part of the AIDA Unified Solids Library package *
 
    4 // * See: https://aidasoft.web.cern.ch/USolids                        *
 
    5 // ********************************************************************
 
    9 // --------------------------------------------------------------------
 
   13 // Implementation of inline methods of UTrap
 
   15 // 12.02.13 Marek Gayer
 
   16 //          Created from original implementation in Geant4
 
   17 // --------------------------------------------------------------------
 
   20 double UTrap::GetZHalfLength() const
 
   26 UVector3 UTrap::GetSymAxis() const
 
   28   double cosTheta = 1.0 / std::sqrt(1 + fTthetaCphi * fTthetaCphi +
 
   29                                     fTthetaSphi * fTthetaSphi) ;
 
   31   return UVector3(fTthetaCphi * cosTheta,
 
   32                   fTthetaSphi * cosTheta,
 
   37 double UTrap::GetYHalfLength1() const
 
   43 double UTrap::GetXHalfLength1() const
 
   49 double UTrap::GetXHalfLength2() const
 
   55 double UTrap::GetTanAlpha1() const
 
   61 double UTrap::GetYHalfLength2() const
 
   67 double UTrap::GetXHalfLength3() const
 
   73 double UTrap::GetXHalfLength4() const
 
   79 double UTrap::GetTanAlpha2() const
 
   85 double UTrap::GetThetaCphi() const
 
   91 double UTrap::GetThetaSphi() const
 
   97 UTrapSidePlane UTrap::GetSidePlane(int n) const
 
  103 double UTrap::GetFaceArea(const UVector3& p0, const UVector3& p1,
 
  104                           const UVector3& p2, const UVector3& p3)
 
  106   double area = 0.5 * ((p1 - p0).Cross(p2 - p1).Mag() + (p3 - p2).Cross(p0 - p3).Mag());
 
  111 double UTrap::Capacity()
 
  113   if (fCubicVolume != 0.)
 
  119     fCubicVolume = fDz * ((fDx1 + fDx2 + fDx3 + fDx4) * (fDy1 + fDy2)
 
  120                           + (fDx4 + fDx3 - fDx2 - fDx1) * (fDy2 - fDy1) / 3);
 
  126 double UTrap::SurfaceArea()
 
  128   if (fSurfaceArea != 0.)
 
  134     UVector3 ba(fDx1 - fDx2 + fTalpha1 * 2 * fDy1, 2 * fDy1, 0);
 
  135     UVector3 bc(2 * fDz * fTthetaCphi - (fDx4 - fDx2) + fTalpha2 * fDy2 - fTalpha1 * fDy1,
 
  136                 2 * fDz * fTthetaSphi + fDy2 - fDy1, 2 * fDz);
 
  137     UVector3 dc(-fDx4 + fDx3 + 2 * fTalpha2 * fDy2, 2 * fDy2, 0);
 
  138     UVector3 da(-2 * fDz * fTthetaCphi - (fDx1 - fDx3) - fTalpha1 * fDy1 + fTalpha2 * fDy2,
 
  139                 -2 * fDz * fTthetaSphi - fDy1 + fDy2, -2 * fDz);
 
  141     UVector3 ef(fDx2 - fDx1 + 2 * fTalpha1 * fDy1, 2 * fDy1, 0);
 
  142     UVector3 eh(2 * fDz * fTthetaCphi + fDx3 - fDx1 + fTalpha1 * fDy1 - fTalpha2 * fDy2,
 
  143                 2 * fDz * fTthetaSphi - fDy2 + fDy1, 2 * fDz);
 
  144     UVector3 gh(fDx3 - fDx4 - 2 * fTalpha2 * fDy2, -2 * fDy2, 0);
 
  145     UVector3 gf(-2 * fDz * fTthetaCphi + fDx2 - fDx4 + fTalpha1 * fDy1 - fTalpha2 * fDy2,
 
  146                 -2 * fDz * fTthetaSphi + fDy1 - fDy2, -2 * fDz);
 
  150     double babc = cr.Mag();
 
  152     double dcda = cr.Mag();
 
  154     double efeh = cr.Mag();
 
  156     double ghgf = cr.Mag();
 
  158     fSurfaceArea = 2 * fDy1 * (fDx1 + fDx2) + 2 * fDy2 * (fDx3 + fDx4)
 
  160                    * std::sqrt(4 * fDz * fDz + std::pow(fDy2 - fDy1 - 2 * fDz * fTthetaSphi, 2))
 
  162                    * std::sqrt(4 * fDz * fDz + std::pow(fDy2 - fDy1 + 2 * fDz * fTthetaSphi, 2))
 
  163                    + 0.5 * (babc + dcda + efeh + ghgf);