Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VUFacet.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration and of QinetiQ Ltd, *
20 // * subject to DEFCON 705 IPR conditions. *
21 // * By using, copying, modifying or distributing the software (or *
22 // * any work based on the software) you agree to acknowledge its *
23 // * use in resulting scientific publications, and indicate your *
24 // * acceptance of all terms of the Geant4 Software license. *
25 // ********************************************************************
26 //
27 //
28 // $Id: VUFacet.cc,v 1.11 2010-09-23 10:30:07 gcosmo Exp $
29 // GEANT4 tag $Name: not supported by cvs2svn $
30 //
31 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 //
33 //
34 // Author: Marek Gayer, started from original implementation by P R Truscott, 2004
35 //
36 
37 #include "VUFacet.hh"
38 #include "VUSolid.hh"
39 
40 using namespace std;
41 
43 {
44  double tolerance = kCarTolerance*kCarTolerance/4.0;
45 
46  if (GetNumberOfVertices() != right.GetNumberOfVertices())
47  return false;
48  else if ((GetCircumcentre()-right.GetCircumcentre()).Mag2() > tolerance)
49  return false;
50  else if (std::fabs((right.GetSurfaceNormal()).Dot(GetSurfaceNormal())) < 0.9999999999)
51  return false;
52 
53  bool coincident = true;
54  int i = 0;
55  do
56  {
57  coincident = false;
58  int j = 0;
59  do
60  {
61  coincident = (GetVertex(i)-right.GetVertex(j)).Mag2() < tolerance;
62  } while (!coincident && ++j < GetNumberOfVertices());
63  } while (coincident && ++i < GetNumberOfVertices());
64 
65  return coincident;
66 }
67 
68 ///////////////////////////////////////////////////////////////////////////////
69 //
71 {
72  int n = GetNumberOfVertices();
73  for (int i = 0; i < n; ++i)
74  SetVertex(i, GetVertex(i) + v);
75 }
76 
77 ///////////////////////////////////////////////////////////////////////////////
78 //
79 std::ostream &VUFacet::StreamInfo(std::ostream &os) const
80 {
81  os << endl;
82  os << "*********************************************************************" << endl;
83  os << "FACET TYPE = " << GetEntityType() << endl;
84  os << "ABSOLUTE VECTORS = " << endl;
85  int n = GetNumberOfVertices();
86  for (int i = 0; i < n; ++i)
87  os << "P[" << i << "] = " << GetVertex(i) << endl;
88 
89  /*
90  os << "RELATIVE VECTORS = " << endl;
91  for (vector<UVector3>::const_iterator it=E.begin(); it!=E.end(); it++)
92  { os << "E[" << it-E.begin()+1 << "] = " << *it << endl; }
93  */
94 
95  os << "*********************************************************************" << endl;
96 
97  return os;
98 }
99 
100 bool VUFacet::IsInside (const UVector3 &p) const
101 {
102  UVector3 d = p - GetVertex(0);
103  double displacement = d.Dot(GetSurfaceNormal());
104  return displacement <= 0.0;
105 }
106 
107 const double VUFacet::dirTolerance = 1.0E-14;
109 // G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
static const double dirTolerance
Definition: VUFacet.hh:88
bool operator==(const VUFacet &right) const
Definition: VUFacet.cc:42
virtual int GetNumberOfVertices() const =0
const char * p
Definition: xmltok.h:285
std::ostream & StreamInfo(std::ostream &os) const
Definition: VUFacet.cc:79
virtual UVector3 GetVertex(int i) const =0
void ApplyTranslation(const UVector3 v)
Definition: VUFacet.cc:70
static double Tolerance()
Definition: VUSolid.hh:127
virtual UVector3 GetSurfaceNormal() const =0
virtual UVector3 GetCircumcentre() const =0
const G4int n
double Dot(const UVector3 &) const
Definition: UVector3.hh:257
bool IsInside(const UVector3 &p) const
Definition: VUFacet.cc:100
static const double kCarTolerance
Definition: VUFacet.hh:89