G4ThreeMat.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.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // ----------------------------------------------------------------------
00030 // GEANT 4 class source file
00031 //
00032 // G4ThreeMat.cc
00033 //
00034 // ----------------------------------------------------------------------
00035 
00036 #include "G4ThreeMat.hh"
00037 
00038 G4ThreeMat::G4ThreeMat()
00039 {  
00040   //  default (null) constructor 
00041   for ( G4int i = 0; i < 3 ; i++ )
00042   {
00043     row[i]    = G4Vector3D( 0., 0., 0. );
00044     column[i] = G4Vector3D( 0., 0., 0. );
00045     
00046     for ( G4int j = 0; j < 3 ; j++ ) 
00047       element[i][j] = 0.;
00048   }
00049 }
00050 
00051 
00052 G4ThreeMat::G4ThreeMat( G4double a[3][3] )
00053 {
00054   //  constructor to make matrix from array
00055   for ( G4int i = 0; i < 3 ; i++ )
00056   {
00057     row[i]    = G4Vector3D( a[i][0], a[i][1], a[i][2] );
00058     column[i] = G4Vector3D( a[0][i], a[1][i], a[2][i] );
00059     
00060     for ( G4int j = 0; j < 3 ; j++ ) 
00061       element[i][j] = a[i][j];
00062   }
00063 }
00064 
00065 
00066 G4ThreeMat::~G4ThreeMat()
00067 {
00068 }
00069 
00070 
00071 G4ThreeMat::G4ThreeMat( const G4ThreeMat& mat )
00072 { 
00073   //  copy constructor
00074   for ( G4int i = 0; i < 3 ; i++ )
00075   {
00076     row[i]    = mat.row[i];
00077     column[i] = mat.column[i];
00078     
00079     for ( G4int j = 0; j < 3 ; j++ ) 
00080       element[i][j] = mat.element[i][j];
00081   }
00082 }
00083 
00084 
00085 const char* G4ThreeMat::NameOf() const
00086 {
00087   return "G4ThreeMat";
00088 }
00089 
00090 
00091 std::ostream& operator<<( std::ostream& os, const G4ThreeMat& mat )
00092 {
00093   // overwrite output operator << to Print out G4ThreeMat objects
00094   // using the PrintOn function defined below
00095   mat.PrintOn( os );
00096   return os;
00097 }
00098 
00099 
00100 void G4ThreeMat::PrintOn( std::ostream& os ) const
00101 {
00102   // printing function using C++ std::ostream class
00103   os << "[ " << element[0][0] << "\t" 
00104      << element[0][1] << "\t"
00105      << element[0][2] << "\n  "
00106      << element[1][0] << "\t"
00107      << element[1][1] << "\t"
00108      << element[1][2] << "\n  "
00109      << element[2][0] << "\t"
00110      << element[2][1] << "\t"
00111      << element[2][2] << " ]\n";
00112   /*
00113     for ( G4int i = 0; i < 3; i++ ) {
00114     os << "row   [" << i << "] " << row[i] << "\n"
00115     << "column[" << i << "] " << column[i] << "\n";
00116     }
00117     */
00118 }
00119 
00120 
00121 G4int G4ThreeMat::operator==( const G4ThreeMat& mat ) const
00122 {
00123   for ( G4int i = 0; i < 3 ; i++ ) 
00124   {
00125     for ( G4int j = 0; j < 3 ; j++ ) 
00126     {
00127       if ( element[i][j] != mat.element[i][j] )
00128         return 0;
00129     }
00130   }
00131 
00132   return 1;
00133 }
00134 
00135 
00136 G4ThreeMat& G4ThreeMat::operator=( const G4ThreeMat& mat )
00137 { 
00138   if (&mat == this) return *this;
00139   for ( G4int i = 0; i < 3 ; i++ )
00140   {
00141     row[i]    = mat.row[i];
00142     column[i] = mat.column[i];
00143 
00144     for ( G4int j = 0; j < 3 ; j++ ) 
00145       element[i][j] = mat.element[i][j];
00146   }
00147   return *this;
00148 }
00149 
00150 
00151 G4double G4ThreeMat::Determinant() const
00152 { 
00153   //  Determinant of a three by three matrix
00154   return element[0][0] * ( element[1][1] * element[2][2]
00155                                     -  element[2][1] * element[1][2] )
00156     - element[0][1] * ( element[1][0] * element[2][2]
00157                         -  element[2][0] * element[1][2] )
00158     + element[0][2] * ( element[1][0] * element[2][1]
00159                         -  element[2][0] * element[1][1] );
00160 }

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