Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ThreeMat.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. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id$
28 //
29 // ----------------------------------------------------------------------
30 // GEANT 4 class source file
31 //
32 // G4ThreeMat.cc
33 //
34 // ----------------------------------------------------------------------
35 
36 #include "G4ThreeMat.hh"
37 
39 {
40  // default (null) constructor
41  for ( G4int i = 0; i < 3 ; i++ )
42  {
43  row[i] = G4Vector3D( 0., 0., 0. );
44  column[i] = G4Vector3D( 0., 0., 0. );
45 
46  for ( G4int j = 0; j < 3 ; j++ )
47  element[i][j] = 0.;
48  }
49 }
50 
51 
53 {
54  // constructor to make matrix from array
55  for ( G4int i = 0; i < 3 ; i++ )
56  {
57  row[i] = G4Vector3D( a[i][0], a[i][1], a[i][2] );
58  column[i] = G4Vector3D( a[0][i], a[1][i], a[2][i] );
59 
60  for ( G4int j = 0; j < 3 ; j++ )
61  element[i][j] = a[i][j];
62  }
63 }
64 
65 
67 {
68 }
69 
70 
72 {
73  // copy constructor
74  for ( G4int i = 0; i < 3 ; i++ )
75  {
76  row[i] = mat.row[i];
77  column[i] = mat.column[i];
78 
79  for ( G4int j = 0; j < 3 ; j++ )
80  element[i][j] = mat.element[i][j];
81  }
82 }
83 
84 
85 const char* G4ThreeMat::NameOf() const
86 {
87  return "G4ThreeMat";
88 }
89 
90 
91 std::ostream& operator<<( std::ostream& os, const G4ThreeMat& mat )
92 {
93  // overwrite output operator << to Print out G4ThreeMat objects
94  // using the PrintOn function defined below
95  mat.PrintOn( os );
96  return os;
97 }
98 
99 
100 void G4ThreeMat::PrintOn( std::ostream& os ) const
101 {
102  // printing function using C++ std::ostream class
103  os << "[ " << element[0][0] << "\t"
104  << element[0][1] << "\t"
105  << element[0][2] << "\n "
106  << element[1][0] << "\t"
107  << element[1][1] << "\t"
108  << element[1][2] << "\n "
109  << element[2][0] << "\t"
110  << element[2][1] << "\t"
111  << element[2][2] << " ]\n";
112  /*
113  for ( G4int i = 0; i < 3; i++ ) {
114  os << "row [" << i << "] " << row[i] << "\n"
115  << "column[" << i << "] " << column[i] << "\n";
116  }
117  */
118 }
119 
120 
122 {
123  for ( G4int i = 0; i < 3 ; i++ )
124  {
125  for ( G4int j = 0; j < 3 ; j++ )
126  {
127  if ( element[i][j] != mat.element[i][j] )
128  return 0;
129  }
130  }
131 
132  return 1;
133 }
134 
135 
137 {
138  if (&mat == this) return *this;
139  for ( G4int i = 0; i < 3 ; i++ )
140  {
141  row[i] = mat.row[i];
142  column[i] = mat.column[i];
143 
144  for ( G4int j = 0; j < 3 ; j++ )
145  element[i][j] = mat.element[i][j];
146  }
147  return *this;
148 }
149 
150 
152 {
153  // Determinant of a three by three matrix
154  return element[0][0] * ( element[1][1] * element[2][2]
155  - element[2][1] * element[1][2] )
156  - element[0][1] * ( element[1][0] * element[2][2]
157  - element[2][0] * element[1][2] )
158  + element[0][2] * ( element[1][0] * element[2][1]
159  - element[2][0] * element[1][1] );
160 }