G4VFacet.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration and of QinetiQ Ltd,   *
00020 // * subject to DEFCON 705 IPR conditions.                            *
00021 // * By using,  copying,  modifying or  distributing the software (or *
00022 // * any work based  on the software)  you  agree  to acknowledge its *
00023 // * use  in  resulting  scientific  publications,  and indicate your *
00024 // * acceptance of all terms of the Geant4 Software license.          *
00025 // ********************************************************************
00026 //
00027 //
00028 // $Id: G4VFacet.cc 67011 2013-01-29 16:17:41Z gcosmo $
00029 //
00030 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00031 //
00032 // CHANGE HISTORY
00033 // --------------
00034 //
00035 // 31 October 2004, P R Truscott, QinetiQ Ltd, UK - Created.
00036 // 12 October 2012, M Gayer, CERN, - Reviewed optimized implementation.
00037 //
00038 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00039 
00040 #include "G4VFacet.hh"
00041 #include "globals.hh"
00042 #include "geomdefs.hh"
00043 #include "G4GeometryTolerance.hh"
00044 
00045 using namespace std;
00046 
00047 const G4double G4VFacet::dirTolerance = 1.0E-14;
00048 const G4double G4VFacet::kCarTolerance =
00049       G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
00050 
00052 //
00053 G4VFacet::~G4VFacet()
00054 {
00055 }
00056 
00058 //
00059 G4bool G4VFacet::operator== (const G4VFacet &right) const
00060 {
00061   G4double tolerance = kCarTolerance*kCarTolerance/4.0;
00062 
00063   if (GetNumberOfVertices() != right.GetNumberOfVertices())
00064     return false;
00065   else if ((GetCircumcentre()-right.GetCircumcentre()).mag2() > tolerance)
00066     return false;
00067   else if (std::fabs((right.GetSurfaceNormal()).dot(GetSurfaceNormal())) < 0.9999999999)
00068     return false;
00069 
00070   G4bool coincident  = true;
00071   G4int i = 0;
00072   do
00073   {
00074     coincident = false;
00075     G4int j   = 0; 
00076     do
00077     {
00078       coincident = (GetVertex(i)-right.GetVertex(j)).mag2() < tolerance;
00079     } while (!coincident && ++j < GetNumberOfVertices());
00080   } while (coincident && ++i < GetNumberOfVertices());
00081 
00082   return coincident;
00083 }
00084 
00086 //
00087 void G4VFacet::ApplyTranslation(const G4ThreeVector v)
00088 {
00089   G4int n = GetNumberOfVertices();
00090   for (G4int i = 0; i < n; ++i)
00091   {
00092     SetVertex(i, GetVertex(i) + v);
00093   }
00094 }
00095 
00097 //
00098 std::ostream &G4VFacet::StreamInfo(std::ostream &os) const
00099 {
00100   os << G4endl;
00101   os << "*********************************************************************"
00102      << G4endl;
00103   os << "FACET TYPE       = " << GetEntityType() << G4endl;
00104   os << "ABSOLUTE VECTORS = " << G4endl;
00105   G4int n = GetNumberOfVertices();
00106   for (G4int i = 0; i < n; ++i)
00107     os << "P[" << i << "]      = " << GetVertex(i) << G4endl;
00108   os << "*********************************************************************"
00109      << G4endl;
00110 
00111   return os;
00112 }
00113 
00114 G4bool G4VFacet::IsInside (const G4ThreeVector &p) const
00115 {
00116   G4ThreeVector d =  p - GetVertex(0);
00117   G4double displacement = d.dot(GetSurfaceNormal());
00118   return displacement <= 0.0;
00119 }

Generated on Mon May 27 17:50:12 2013 for Geant4 by  doxygen 1.4.7