| [831] | 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: G4ThreeMat.cc,v 1.8 2006/06/29 18:42:56 gunter Exp $
|
|---|
| [1337] | 28 | // GEANT4 tag $Name: geant4-09-04-beta-01 $
|
|---|
| [831] | 29 | //
|
|---|
| 30 | // ----------------------------------------------------------------------
|
|---|
| 31 | // GEANT 4 class source file
|
|---|
| 32 | //
|
|---|
| 33 | // G4ThreeMat.cc
|
|---|
| 34 | //
|
|---|
| 35 | // ----------------------------------------------------------------------
|
|---|
| 36 |
|
|---|
| 37 | #include "G4ThreeMat.hh"
|
|---|
| 38 |
|
|---|
| 39 | G4ThreeMat::G4ThreeMat()
|
|---|
| 40 | {
|
|---|
| 41 | // default (null) constructor
|
|---|
| 42 | for ( G4int i = 0; i < 3 ; i++ )
|
|---|
| 43 | {
|
|---|
| 44 | row[i] = G4Vector3D( 0., 0., 0. );
|
|---|
| 45 | column[i] = G4Vector3D( 0., 0., 0. );
|
|---|
| 46 |
|
|---|
| 47 | for ( G4int j = 0; j < 3 ; j++ )
|
|---|
| 48 | element[i][j] = 0.;
|
|---|
| 49 | }
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 | G4ThreeMat::G4ThreeMat( G4double a[3][3] )
|
|---|
| 54 | {
|
|---|
| 55 | // constructor to make matrix from array
|
|---|
| 56 | for ( G4int i = 0; i < 3 ; i++ )
|
|---|
| 57 | {
|
|---|
| 58 | row[i] = G4Vector3D( a[i][0], a[i][1], a[i][2] );
|
|---|
| 59 | column[i] = G4Vector3D( a[0][i], a[1][i], a[2][i] );
|
|---|
| 60 |
|
|---|
| 61 | for ( G4int j = 0; j < 3 ; j++ )
|
|---|
| 62 | element[i][j] = a[i][j];
|
|---|
| 63 | }
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 | G4ThreeMat::~G4ThreeMat()
|
|---|
| 68 | {
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 | G4ThreeMat::G4ThreeMat( const G4ThreeMat& m )
|
|---|
| 73 | {
|
|---|
| 74 | // copy constructor
|
|---|
| 75 | for ( G4int i = 0; i < 3 ; i++ )
|
|---|
| 76 | {
|
|---|
| 77 | row[i] = m.row[i];
|
|---|
| 78 | column[i] = m.column[i];
|
|---|
| 79 |
|
|---|
| 80 | for ( G4int j = 0; j < 3 ; j++ )
|
|---|
| 81 | element[i][j] = m.element[i][j];
|
|---|
| 82 | }
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 | const char* G4ThreeMat::NameOf() const
|
|---|
| 87 | {
|
|---|
| 88 | return "G4ThreeMat";
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 | std::ostream& operator<<( std::ostream& os, const G4ThreeMat& m )
|
|---|
| 93 | {
|
|---|
| 94 | // overwrite output operator << to Print out G4ThreeMat objects
|
|---|
| 95 | // using the PrintOn function defined below
|
|---|
| 96 | m.PrintOn( os );
|
|---|
| 97 | return os;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 | void G4ThreeMat::PrintOn( std::ostream& os ) const
|
|---|
| 102 | {
|
|---|
| 103 | // printing function using C++ std::ostream class
|
|---|
| 104 | os << "[ " << element[0][0] << "\t"
|
|---|
| 105 | << element[0][1] << "\t"
|
|---|
| 106 | << element[0][2] << "\n "
|
|---|
| 107 | << element[1][0] << "\t"
|
|---|
| 108 | << element[1][1] << "\t"
|
|---|
| 109 | << element[1][2] << "\n "
|
|---|
| 110 | << element[2][0] << "\t"
|
|---|
| 111 | << element[2][1] << "\t"
|
|---|
| 112 | << element[2][2] << " ]\n";
|
|---|
| 113 | /*
|
|---|
| 114 | for ( G4int i = 0; i < 3; i++ ) {
|
|---|
| 115 | os << "row [" << i << "] " << row[i] << "\n"
|
|---|
| 116 | << "column[" << i << "] " << column[i] << "\n";
|
|---|
| 117 | }
|
|---|
| 118 | */
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 | G4int G4ThreeMat::operator==( const G4ThreeMat& m ) const
|
|---|
| 123 | {
|
|---|
| 124 | for ( G4int i = 0; i < 3 ; i++ )
|
|---|
| 125 | {
|
|---|
| 126 | for ( G4int j = 0; j < 3 ; j++ )
|
|---|
| 127 | {
|
|---|
| 128 | if ( element[i][j] != m.element[i][j] )
|
|---|
| 129 | return 0;
|
|---|
| 130 | }
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | return 1;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 | G4ThreeMat& G4ThreeMat::operator=( const G4ThreeMat& m )
|
|---|
| 138 | {
|
|---|
| 139 | if (&m == this) return *this;
|
|---|
| 140 | for ( G4int i = 0; i < 3 ; i++ )
|
|---|
| 141 | {
|
|---|
| 142 | row[i] = m.row[i];
|
|---|
| 143 | column[i] = m.column[i];
|
|---|
| 144 |
|
|---|
| 145 | for ( G4int j = 0; j < 3 ; j++ )
|
|---|
| 146 | element[i][j] = m.element[i][j];
|
|---|
| 147 | }
|
|---|
| 148 | return *this;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 | G4double G4ThreeMat::Determinant() const
|
|---|
| 153 | {
|
|---|
| 154 | // Determinant of a three by three matrix
|
|---|
| 155 | return element[0][0] * ( element[1][1] * element[2][2]
|
|---|
| 156 | - element[2][1] * element[1][2] )
|
|---|
| 157 | - element[0][1] * ( element[1][0] * element[2][2]
|
|---|
| 158 | - element[2][0] * element[1][2] )
|
|---|
| 159 | + element[0][2] * ( element[1][0] * element[2][1]
|
|---|
| 160 | - element[2][0] * element[1][1] );
|
|---|
| 161 | }
|
|---|