Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // >> 23 // >> 24 // $Id: G4AffineTransform.icc,v 1.7 2003/11/02 14:01:21 gcosmo Exp $ >> 25 // GEANT4 tag $Name: geant4-06-00-patch-01 $ >> 26 // >> 27 // 26 // G4AffineTransformation Inline implementatio 28 // G4AffineTransformation Inline implementation 27 // 29 // 28 // ------------------------------------------- 30 // -------------------------------------------------------------------- 29 31 30 inline G4AffineTransform::G4AffineTransform() 32 inline G4AffineTransform::G4AffineTransform() 31 : rxx(1),rxy(0),rxz(0), 33 : rxx(1),rxy(0),rxz(0), 32 ryx(0),ryy(1),ryz(0), 34 ryx(0),ryy(1),ryz(0), 33 rzx(0),rzy(0),rzz(1), 35 rzx(0),rzy(0),rzz(1), 34 tx(0),ty(0),tz(0) 36 tx(0),ty(0),tz(0) 35 {} 37 {} 36 38 37 inline G4AffineTransform::G4AffineTransform(co 39 inline G4AffineTransform::G4AffineTransform(const G4ThreeVector& tlate) 38 : rxx(1),rxy(0),rxz(0), 40 : rxx(1),rxy(0),rxz(0), 39 ryx(0),ryy(1),ryz(0), 41 ryx(0),ryy(1),ryz(0), 40 rzx(0),rzy(0),rzz(1), 42 rzx(0),rzy(0),rzz(1), 41 tx(tlate.x()),ty(tlate.y()),tz(tlate.z()) 43 tx(tlate.x()),ty(tlate.y()),tz(tlate.z()) 42 {} 44 {} 43 45 44 inline G4AffineTransform::G4AffineTransform(co 46 inline G4AffineTransform::G4AffineTransform(const G4RotationMatrix& rot) 45 : rxx(rot.xx()),rxy(rot.xy()),rxz(rot.xz()), 47 : rxx(rot.xx()),rxy(rot.xy()),rxz(rot.xz()), 46 ryx(rot.yx()),ryy(rot.yy()),ryz(rot.yz()), 48 ryx(rot.yx()),ryy(rot.yy()),ryz(rot.yz()), 47 rzx(rot.zx()),rzy(rot.zy()),rzz(rot.zz()), 49 rzx(rot.zx()),rzy(rot.zy()),rzz(rot.zz()), 48 tx(0),ty(0),tz(0) 50 tx(0),ty(0),tz(0) 49 {} 51 {} 50 52 51 inline G4AffineTransform::G4AffineTransform( c 53 inline G4AffineTransform::G4AffineTransform( const G4RotationMatrix& rot, 52 c << 54 const G4ThreeVector& tlate ) 53 : rxx(rot.xx()),rxy(rot.xy()),rxz(rot.xz()), 55 : rxx(rot.xx()),rxy(rot.xy()),rxz(rot.xz()), 54 ryx(rot.yx()),ryy(rot.yy()),ryz(rot.yz()), 56 ryx(rot.yx()),ryy(rot.yy()),ryz(rot.yz()), 55 rzx(rot.zx()),rzy(rot.zy()),rzz(rot.zz()), 57 rzx(rot.zx()),rzy(rot.zy()),rzz(rot.zz()), 56 tx(tlate.x()),ty(tlate.y()),tz(tlate.z()) 58 tx(tlate.x()),ty(tlate.y()),tz(tlate.z()) 57 {} 59 {} 58 60 59 inline G4AffineTransform::G4AffineTransform( c << 61 inline G4AffineTransform::G4AffineTransform( const G4RotationMatrix *rot, 60 c << 62 const G4ThreeVector& tlate) 61 : tx(tlate.x()),ty(tlate.y()),tz(tlate.z()) 63 : tx(tlate.x()),ty(tlate.y()),tz(tlate.z()) 62 { 64 { 63 if (rot != nullptr) << 65 if (rot) 64 { << 66 { 65 rxx=rot->xx();rxy=rot->xy();rxz=rot->xz(); << 67 rxx=rot->xx();rxy=rot->xy();rxz=rot->xz(); 66 ryx=rot->yx();ryy=rot->yy();ryz=rot->yz(); << 68 ryx=rot->yx();ryy=rot->yy();ryz=rot->yz(); 67 rzx=rot->zx();rzy=rot->zy();rzz=rot->zz(); << 69 rzx=rot->zx();rzy=rot->zy();rzz=rot->zz(); 68 } << 70 } 69 else 71 else 70 { << 72 { 71 rxx=1; rxy=0; rxz=0; << 73 rxx=1; rxy=0; rxz=0; 72 ryx=0; ryy=1; ryz=0; << 74 ryx=0; ryy=1; ryz=0; 73 rzx=0; rzy=0; rzz=1; << 75 rzx=0; rzy=0; rzz=1; 74 } << 76 } 75 } 77 } 76 78 77 inline << 79 inline 78 G4AffineTransform:: 80 G4AffineTransform:: 79 G4AffineTransform( const G4double prxx,const G 81 G4AffineTransform( const G4double prxx,const G4double prxy,const G4double prxz, 80 const G4double pryx,const G 82 const G4double pryx,const G4double pryy,const G4double pryz, 81 const G4double przx,const G 83 const G4double przx,const G4double przy,const G4double przz, 82 const G4double ptx,const G4 << 84 const G4double ptx,const G4double pty,const G4double ptz) 83 : rxx(prxx),rxy(prxy),rxz(prxz), 85 : rxx(prxx),rxy(prxy),rxz(prxz), 84 ryx(pryx),ryy(pryy),ryz(pryz), 86 ryx(pryx),ryy(pryy),ryz(pryz), 85 rzx(przx),rzy(przy),rzz(przz), 87 rzx(przx),rzy(przy),rzz(przz), 86 tx(ptx),ty(pty),tz(ptz) 88 tx(ptx),ty(pty),tz(ptz) 87 {} 89 {} 88 90 89 inline G4AffineTransform& << 90 G4AffineTransform::operator = (const G4AffineT << 91 { << 92 if (this == &rhs) { return *this; } << 93 rxx = rhs.rxx; rxy = rhs.rxy; rxz = rhs.rxz; << 94 ryx = rhs.ryx; ryy = rhs.ryy; ryz = rhs.ryz; << 95 rzx = rhs.rzx; rzy = rhs.rzy; rzz = rhs.rzz; << 96 tx = rhs.tx; ty = rhs.ty; tz = rhs.tz; << 97 return *this; << 98 } << 99 << 100 inline G4AffineTransform 91 inline G4AffineTransform 101 G4AffineTransform::operator * (const G4AffineT 92 G4AffineTransform::operator * (const G4AffineTransform& tf) const 102 { 93 { 103 return G4AffineTransform(rxx*tf.rxx+rxy*tf.r << 94 return G4AffineTransform( 104 rxx*tf.rxy+rxy*tf.r << 95 rxx*tf.rxx+rxy*tf.ryx+rxz*tf.rzx, 105 rxx*tf.rxz+rxy*tf.r << 96 rxx*tf.rxy+rxy*tf.ryy+rxz*tf.rzy, 106 << 97 rxx*tf.rxz+rxy*tf.ryz+rxz*tf.rzz, 107 ryx*tf.rxx+ryy*tf.r << 98 108 ryx*tf.rxy+ryy*tf.r << 99 ryx*tf.rxx+ryy*tf.ryx+ryz*tf.rzx, 109 ryx*tf.rxz+ryy*tf.r << 100 ryx*tf.rxy+ryy*tf.ryy+ryz*tf.rzy, 110 << 101 ryx*tf.rxz+ryy*tf.ryz+ryz*tf.rzz, 111 rzx*tf.rxx+rzy*tf.r << 102 112 rzx*tf.rxy+rzy*tf.r << 103 rzx*tf.rxx+rzy*tf.ryx+rzz*tf.rzx, 113 rzx*tf.rxz+rzy*tf.r << 104 rzx*tf.rxy+rzy*tf.ryy+rzz*tf.rzy, 114 << 105 rzx*tf.rxz+rzy*tf.ryz+rzz*tf.rzz, 115 tx*tf.rxx+ty*tf.ryx << 106 116 tx*tf.rxy+ty*tf.ryy << 107 tx*tf.rxx+ty*tf.ryx+tz*tf.rzx+tf.tx, 117 tx*tf.rxz+ty*tf.ryz << 108 tx*tf.rxy+ty*tf.ryy+tz*tf.rzy+tf.ty, >> 109 tx*tf.rxz+ty*tf.ryz+tz*tf.rzz+tf.tz); 118 } 110 } 119 111 120 inline G4AffineTransform& 112 inline G4AffineTransform& 121 G4AffineTransform::operator *= (const G4Affine 113 G4AffineTransform::operator *= (const G4AffineTransform& tf) 122 { 114 { 123 // Use temporaries for `in place' compound t << 115 // Use temporaries for `in place' compound transform computation 124 // << 116 125 G4double nrxx=rxx*tf.rxx+rxy*tf.ryx+rxz*tf.r << 117 G4double nrxx=rxx*tf.rxx+rxy*tf.ryx+rxz*tf.rzx; 126 G4double nrxy=rxx*tf.rxy+rxy*tf.ryy+rxz*tf.r << 118 G4double nrxy=rxx*tf.rxy+rxy*tf.ryy+rxz*tf.rzy; 127 G4double nrxz=rxx*tf.rxz+rxy*tf.ryz+rxz*tf.r << 119 G4double nrxz=rxx*tf.rxz+rxy*tf.ryz+rxz*tf.rzz; 128 << 120 129 G4double nryx=ryx*tf.rxx+ryy*tf.ryx+ryz*tf.r << 121 G4double nryx=ryx*tf.rxx+ryy*tf.ryx+ryz*tf.rzx; 130 G4double nryy=ryx*tf.rxy+ryy*tf.ryy+ryz*tf.r << 122 G4double nryy=ryx*tf.rxy+ryy*tf.ryy+ryz*tf.rzy; 131 G4double nryz=ryx*tf.rxz+ryy*tf.ryz+ryz*tf.r << 123 G4double nryz=ryx*tf.rxz+ryy*tf.ryz+ryz*tf.rzz; 132 << 124 133 G4double nrzx=rzx*tf.rxx+rzy*tf.ryx+rzz*tf.r << 125 G4double nrzx=rzx*tf.rxx+rzy*tf.ryx+rzz*tf.rzx; 134 G4double nrzy=rzx*tf.rxy+rzy*tf.ryy+rzz*tf.r << 126 G4double nrzy=rzx*tf.rxy+rzy*tf.ryy+rzz*tf.rzy; 135 G4double nrzz=rzx*tf.rxz+rzy*tf.ryz+rzz*tf.r << 127 G4double nrzz=rzx*tf.rxz+rzy*tf.ryz+rzz*tf.rzz; 136 128 137 G4double ntx=tx*tf.rxx+ty*tf.ryx+tz*tf.rzx+t << 129 G4double ntx=tx*tf.rxx+ty*tf.ryx+tz*tf.rzx+tf.tx; 138 G4double nty=tx*tf.rxy+ty*tf.ryy+tz*tf.rzy+t << 130 G4double nty=tx*tf.rxy+ty*tf.ryy+tz*tf.rzy+tf.ty; 139 G4double ntz=tx*tf.rxz+ty*tf.ryz+tz*tf.rzz+t << 131 G4double ntz=tx*tf.rxz+ty*tf.ryz+tz*tf.rzz+tf.tz; 140 << 132 141 tx=ntx; ty=nty; tz=ntz; << 133 tx=ntx; ty=nty; tz=ntz; 142 rxx=nrxx; rxy=nrxy; rxz=nrxz; << 134 rxx=nrxx; rxy=nrxy; rxz=nrxz; 143 ryx=nryx; ryy=nryy; ryz=nryz; << 135 ryx=nryx; ryy=nryy; ryz=nryz; 144 rzx=nrzx; rzy=nrzy; rzz=nrzz; << 136 rzx=nrzx; rzy=nrzy; rzz=nrzz; 145 137 146 return *this; << 138 return *this; 147 } 139 } 148 140 149 inline G4AffineTransform& 141 inline G4AffineTransform& 150 G4AffineTransform::Product( const G4AffineTran << 142 G4AffineTransform::Product(const G4AffineTransform& tf1, 151 const G4AffineTran << 143 const G4AffineTransform& tf2) 152 { 144 { 153 rxx = tf1.rxx*tf2.rxx + tf1.rxy*tf2.ryx + tf << 145 rxx=tf1.rxx*tf2.rxx + tf1.rxy*tf2.ryx + tf1.rxz*tf2.rzx; 154 rxy = tf1.rxx*tf2.rxy + tf1.rxy*tf2.ryy + tf << 146 rxy=tf1.rxx*tf2.rxy + tf1.rxy*tf2.ryy + tf1.rxz*tf2.rzy; 155 rxz = tf1.rxx*tf2.rxz + tf1.rxy*tf2.ryz + tf << 147 rxz=tf1.rxx*tf2.rxz + tf1.rxy*tf2.ryz + tf1.rxz*tf2.rzz; 156 << 148 157 ryx = tf1.ryx*tf2.rxx + tf1.ryy*tf2.ryx + tf << 149 ryx=tf1.ryx*tf2.rxx + tf1.ryy*tf2.ryx + tf1.ryz*tf2.rzx; 158 ryy = tf1.ryx*tf2.rxy + tf1.ryy*tf2.ryy + tf << 150 ryy=tf1.ryx*tf2.rxy + tf1.ryy*tf2.ryy + tf1.ryz*tf2.rzy; 159 ryz = tf1.ryx*tf2.rxz + tf1.ryy*tf2.ryz + tf << 151 ryz=tf1.ryx*tf2.rxz + tf1.ryy*tf2.ryz + tf1.ryz*tf2.rzz; 160 << 152 161 rzx = tf1.rzx*tf2.rxx + tf1.rzy*tf2.ryx + tf << 153 rzx=tf1.rzx*tf2.rxx + tf1.rzy*tf2.ryx + tf1.rzz*tf2.rzx; 162 rzy = tf1.rzx*tf2.rxy + tf1.rzy*tf2.ryy + tf << 154 rzy=tf1.rzx*tf2.rxy + tf1.rzy*tf2.ryy + tf1.rzz*tf2.rzy; 163 rzz = tf1.rzx*tf2.rxz + tf1.rzy*tf2.ryz + tf << 155 rzz=tf1.rzx*tf2.rxz + tf1.rzy*tf2.ryz + tf1.rzz*tf2.rzz; 164 << 156 165 tx = tf1.tx*tf2.rxx + tf1.ty*tf2.ryx + tf1.t << 157 tx=tf1.tx*tf2.rxx + tf1.ty*tf2.ryx + tf1.tz*tf2.rzx + tf2.tx; 166 ty = tf1.tx*tf2.rxy + tf1.ty*tf2.ryy + tf1.t << 158 ty=tf1.tx*tf2.rxy + tf1.ty*tf2.ryy + tf1.tz*tf2.rzy + tf2.ty; 167 tz = tf1.tx*tf2.rxz + tf1.ty*tf2.ryz + tf1.t << 159 tz=tf1.tx*tf2.rxz + tf1.ty*tf2.ryz + tf1.tz*tf2.rzz + tf2.tz; 168 << 160 169 return *this; << 161 return *this; 170 } 162 } 171 163 172 inline G4AffineTransform& 164 inline G4AffineTransform& 173 G4AffineTransform::InverseProduct( const G4Aff 165 G4AffineTransform::InverseProduct( const G4AffineTransform& tf1, 174 const G4Aff << 166 const G4AffineTransform& tf2) 175 { 167 { 176 if ((tf2.rxx + tf2.ryy + tf2.rzz) == 3.) << 168 G4double itf2tx = - tf2.tx*tf2.rxx - tf2.ty*tf2.rxy - tf2.tz*tf2.rxz; 177 { << 169 G4double itf2ty = - tf2.tx*tf2.ryx - tf2.ty*tf2.ryy - tf2.tz*tf2.ryz; 178 rxx = tf1.rxx; << 170 G4double itf2tz = - tf2.tx*tf2.rzx - tf2.ty*tf2.rzy - tf2.tz*tf2.rzz; 179 rxy = tf1.rxy; << 171 180 rxz = tf1.rxz; << 172 rxx=tf1.rxx*tf2.rxx+tf1.rxy*tf2.rxy+tf1.rxz*tf2.rxz; 181 << 173 rxy=tf1.rxx*tf2.ryx+tf1.rxy*tf2.ryy+tf1.rxz*tf2.ryz; 182 ryx = tf1.ryx; << 174 rxz=tf1.rxx*tf2.rzx+tf1.rxy*tf2.rzy+tf1.rxz*tf2.rzz; 183 ryy = tf1.ryy; << 175 184 ryz = tf1.ryz; << 176 ryx=tf1.ryx*tf2.rxx+tf1.ryy*tf2.rxy+tf1.ryz*tf2.rxz; 185 << 177 ryy=tf1.ryx*tf2.ryx+tf1.ryy*tf2.ryy+tf1.ryz*tf2.ryz; 186 rzx = tf1.rzx; << 178 ryz=tf1.ryx*tf2.rzx+tf1.ryy*tf2.rzy+tf1.ryz*tf2.rzz; 187 rzy = tf1.rzy; << 179 188 rzz = tf1.rzz; << 180 rzx=tf1.rzx*tf2.rxx+tf1.rzy*tf2.rxy+tf1.rzz*tf2.rxz; 189 << 181 rzy=tf1.rzx*tf2.ryx+tf1.rzy*tf2.ryy+tf1.rzz*tf2.ryz; 190 tx = tf1.tx - tf2.tx; << 182 rzz=tf1.rzx*tf2.rzx+tf1.rzy*tf2.rzy+tf1.rzz*tf2.rzz; 191 ty = tf1.ty - tf2.ty; << 183 192 tz = tf1.tz - tf2.tz; << 184 tx=tf1.tx*tf2.rxx+tf1.ty*tf2.rxy+tf1.tz*tf2.rxz+itf2tx; 193 } << 185 ty=tf1.tx*tf2.ryx+tf1.ty*tf2.ryy+tf1.tz*tf2.ryz+itf2ty; 194 else << 186 tz=tf1.tx*tf2.rzx+tf1.ty*tf2.rzy+tf1.tz*tf2.rzz+itf2tz; 195 { << 187 196 G4double tf1rxx = tf1.rxx, tf1rxy = tf1.rx << 188 return *this; 197 rxx = tf1rxx*tf2.rxx + tf1rxy*tf2.rxy + tf << 189 } 198 rxy = tf1rxx*tf2.ryx + tf1rxy*tf2.ryy + tf << 190 199 rxz = tf1rxx*tf2.rzx + tf1rxy*tf2.rzy + tf << 191 inline 200 << 192 G4ThreeVector G4AffineTransform::TransformPoint(const G4ThreeVector& vec) const 201 G4double tf1ryx = tf1.ryx, tf1ryy = tf1.ry << 193 { 202 ryx = tf1ryx*tf2.rxx + tf1ryy*tf2.rxy + tf << 194 return G4ThreeVector( vec.x()*rxx + vec.y()*ryx + vec.z()*rzx + tx, 203 ryy = tf1ryx*tf2.ryx + tf1ryy*tf2.ryy + tf << 195 vec.x()*rxy + vec.y()*ryy + vec.z()*rzy + ty, 204 ryz = tf1ryx*tf2.rzx + tf1ryy*tf2.rzy + tf << 196 vec.x()*rxz + vec.y()*ryz + vec.z()*rzz + tz ); 205 << 197 } 206 G4double tf1rzx = tf1.rzx, tf1rzy = tf1.rz << 198 207 rzx = tf1rzx*tf2.rxx + tf1rzy*tf2.rxy + tf << 199 inline 208 rzy = tf1rzx*tf2.ryx + tf1rzy*tf2.ryy + tf << 200 G4ThreeVector G4AffineTransform::TransformAxis(const G4ThreeVector& axis) const 209 rzz = tf1rzx*tf2.rzx + tf1rzy*tf2.rzy + tf << 201 { 210 << 202 return G4ThreeVector( axis.x()*rxx + axis.y()*ryx + axis.z()*rzx, 211 G4double tf1_2tx = tf1.tx - tf2.tx; << 203 axis.x()*rxy + axis.y()*ryy + axis.z()*rzy, 212 G4double tf1_2ty = tf1.ty - tf2.ty; << 204 axis.x()*rxz + axis.y()*ryz + axis.z()*rzz ); 213 G4double tf1_2tz = tf1.tz - tf2.tz; << 214 tx = tf1_2tx*tf2.rxx + tf1_2ty*tf2.rxy + t << 215 ty = tf1_2tx*tf2.ryx + tf1_2ty*tf2.ryy + t << 216 tz = tf1_2tx*tf2.rzx + tf1_2ty*tf2.rzy + t << 217 } << 218 return *this; << 219 } << 220 << 221 inline G4ThreeVector << 222 G4AffineTransform::TransformPoint(const G4Thre << 223 { << 224 G4double vecx = vec.x(), vecy = vec.y(), vec << 225 return { vecx*rxx + vecy*ryx + vecz*rzx + tx << 226 vecx*rxy + vecy*ryy + vecz*rzy + ty << 227 vecx*rxz + vecy*ryz + vecz*rzz + tz << 228 } << 229 << 230 inline G4ThreeVector << 231 G4AffineTransform::InverseTransformPoint(const << 232 { << 233 G4double vecx = vec.x()-tx, vecy = vec.y()-t << 234 return { vecx*rxx + vecy*rxy + vecz*rxz, << 235 vecx*ryx + vecy*ryy + vecz*ryz, << 236 vecx*rzx + vecy*rzy + vecz*rzz }; << 237 } << 238 << 239 inline G4ThreeVector << 240 G4AffineTransform::TransformAxis(const G4Three << 241 { << 242 G4double axisx = axis.x(), axisy = axis.y(), << 243 return { axisx*rxx + axisy*ryx + axisz*rzx, << 244 axisx*rxy + axisy*ryy + axisz*rzy, << 245 axisx*rxz + axisy*ryz + axisz*rzz } << 246 } << 247 << 248 inline G4ThreeVector << 249 G4AffineTransform::InverseTransformAxis(const << 250 { << 251 G4double axisx = axis.x(), axisy = axis.y(), << 252 return { axisx*rxx + axisy*rxy + axisz*rxz, << 253 axisx*ryx + axisy*ryy + axisz*ryz, << 254 axisx*rzx + axisy*rzy + axisz*rzz } << 255 } 205 } 256 206 257 inline 207 inline 258 void G4AffineTransform::ApplyPointTransform(G4 208 void G4AffineTransform::ApplyPointTransform(G4ThreeVector& vec) const 259 { 209 { 260 G4double vecx = vec.x(), vecy = vec.y(), vec << 210 G4double x = vec.x()*rxx + vec.y()*ryx + vec.z()*rzx + tx; 261 vec.setX( vecx*rxx + vecy*ryx + vecz*rzx + t << 211 G4double y = vec.x()*rxy + vec.y()*ryy + vec.z()*rzy + ty; 262 vec.setY( vecx*rxy + vecy*ryy + vecz*rzy + t << 212 G4double z = vec.x()*rxz + vec.y()*ryz + vec.z()*rzz + tz; 263 vec.setZ( vecx*rxz + vecy*ryz + vecz*rzz + t << 213 >> 214 vec.setX(x); >> 215 vec.setY(y); >> 216 vec.setZ(z); 264 } 217 } 265 218 266 inline 219 inline 267 void G4AffineTransform::ApplyAxisTransform(G4T 220 void G4AffineTransform::ApplyAxisTransform(G4ThreeVector& axis) const 268 { 221 { 269 G4double axisx = axis.x(), axisy = axis.y(), << 222 G4double x = axis.x()*rxx + axis.y()*ryx + axis.z()*rzx; 270 axis.setX( axisx*rxx + axisy*ryx + axisz*rzx << 223 G4double y = axis.x()*rxy + axis.y()*ryy + axis.z()*rzy; 271 axis.setY( axisx*rxy + axisy*ryy + axisz*rzy << 224 G4double z = axis.x()*rxz + axis.y()*ryz + axis.z()*rzz; 272 axis.setZ( axisx*rxz + axisy*ryz + axisz*rzz << 225 >> 226 axis.setX(x); >> 227 axis.setY(y); >> 228 axis.setZ(z); 273 } 229 } 274 230 275 inline 231 inline 276 G4AffineTransform G4AffineTransform::Inverse() 232 G4AffineTransform G4AffineTransform::Inverse() const 277 { 233 { 278 G4double ttx = -tx, tty = -ty, ttz = -tz; << 234 return G4AffineTransform( rxx, ryx, rzx, 279 return G4AffineTransform( rxx, ryx, rzx, << 235 rxy, ryy, rzy, 280 rxy, ryy, rzy, << 236 rxz, ryz, rzz, 281 rxz, ryz, rzz, << 237 282 ttx*rxx + tty*rxy << 238 -tx*rxx - ty*rxy - tz*rxz, 283 ttx*ryx + tty*ryy << 239 -tx*ryx - ty*ryy - tz*ryz, 284 ttx*rzx + tty*rzy << 240 -tx*rzx - ty*rzy - tz*rzz ); 285 } 241 } 286 242 287 inline 243 inline 288 G4AffineTransform& G4AffineTransform::Invert() 244 G4AffineTransform& G4AffineTransform::Invert() 289 { 245 { 290 G4double ttx = -tx, tty = -ty, ttz = -tz; << 246 G4double v1 = -tx*rxx - ty*rxy - tz*rxz; 291 tx = ttx*rxx + tty*rxy + ttz*rxz; << 247 G4double v2 = -tx*ryx - ty*ryy - tz*ryz; 292 ty = ttx*ryx + tty*ryy + ttz*ryz; << 248 G4double v3 = -tx*rzx - ty*rzy - tz*rzz; 293 tz = ttx*rzx + tty*rzy + ttz*rzz; << 249 294 << 250 tx=v1; ty=v2; tz=v3; 295 G4double tmp1=ryx; ryx=rxy; rxy=tmp1; << 251 296 G4double tmp2=rzx; rzx=rxz; rxz=tmp2; << 252 G4double tmp1=ryx; ryx=rxy; rxy=tmp1; 297 G4double tmp3=rzy; rzy=ryz; ryz=tmp3; << 253 G4double tmp2=rzx; rzx=rxz; rxz=tmp2; >> 254 G4double tmp3=rzy; rzy=ryz; ryz=tmp3; >> 255 >> 256 return *this; 298 257 299 return *this; << 300 } 258 } 301 259 302 inline 260 inline 303 G4AffineTransform& G4AffineTransform::operator 261 G4AffineTransform& G4AffineTransform::operator +=(const G4ThreeVector& tlate) 304 { 262 { 305 tx += tlate.x(); << 263 tx += tlate.x(); 306 ty += tlate.y(); << 264 ty += tlate.y(); 307 tz += tlate.z(); << 265 tz += tlate.z(); 308 266 309 return *this; << 267 return *this; 310 } 268 } 311 269 312 inline 270 inline 313 G4AffineTransform& G4AffineTransform::operator 271 G4AffineTransform& G4AffineTransform::operator -=(const G4ThreeVector& tlate) 314 { 272 { 315 tx -= tlate.x(); << 273 tx -= tlate.x(); 316 ty -= tlate.y(); << 274 ty -= tlate.y(); 317 tz -= tlate.z(); << 275 tz -= tlate.z(); 318 276 319 return *this; << 277 return *this; 320 } 278 } 321 279 322 inline 280 inline 323 G4bool G4AffineTransform::operator == (const G 281 G4bool G4AffineTransform::operator == (const G4AffineTransform& tf) const 324 { 282 { 325 return tx==tf.tx&&ty==tf.ty&&tz==tf.tz&& << 283 return (tx==tf.tx&&ty==tf.ty&&tz==tf.tz&& 326 rxx==tf.rxx&&rxy==tf.rxy&&rxz==tf.rxz << 284 rxx==tf.rxx&&rxy==tf.rxy&&rxz==tf.rxz&& 327 ryx==tf.ryx&&ryy==tf.ryy&&ryz==tf.ryz << 285 ryx==tf.ryx&&ryy==tf.ryy&&ryz==tf.ryz&& 328 rzx==tf.rzx&&rzy==tf.rzy&&rzz==tf.rzz << 286 rzx==tf.rzx&&rzy==tf.rzy&&rzz==tf.rzz) ? true : false; 329 } 287 } 330 << 331 inline 288 inline 332 G4bool G4AffineTransform::operator != (const G 289 G4bool G4AffineTransform::operator != (const G4AffineTransform& tf) const 333 { 290 { 334 return tx!=tf.tx||ty!=tf.ty||tz!=tf.tz|| << 291 return (tx!=tf.tx||ty!=tf.ty||tz!=tf.tz|| 335 rxx!=tf.rxx||rxy!=tf.rxy||rxz!=tf.rxz << 292 rxx!=tf.rxx||rxy!=tf.rxy||rxz!=tf.rxz|| 336 ryx!=tf.ryx||ryy!=tf.ryy||ryz!=tf.ryz << 293 ryx!=tf.ryx||ryy!=tf.ryy||ryz!=tf.ryz|| 337 rzx!=tf.rzx||rzy!=tf.rzy||rzz!=tf.rzz << 294 rzx!=tf.rzx||rzy!=tf.rzy||rzz!=tf.rzz) ? true : false; 338 } 295 } 339 296 340 inline 297 inline 341 G4double G4AffineTransform::operator [] (const 298 G4double G4AffineTransform::operator [] (const G4int n) const 342 { 299 { 343 G4double v = 0.0; << 300 G4double v = 0.0; 344 switch(n) << 301 switch(n) 345 { << 302 { 346 case 0: << 303 case 0: 347 v=rxx; << 304 v=rxx; 348 break; << 305 break; 349 case 1: << 306 case 1: 350 v=rxy; << 307 v=rxy; 351 break; << 308 break; 352 case 2: << 309 case 2: 353 v=rxz; << 310 v=rxz; 354 break; << 311 break; 355 case 4: << 312 case 4: 356 v=ryx; << 313 v=ryx; 357 break; << 314 break; 358 case 5: << 315 case 5: 359 v=ryy; << 316 v=ryy; 360 break; << 317 break; 361 case 6: << 318 case 6: 362 v=ryz; << 319 v=ryz; 363 break; << 320 break; 364 case 8: << 321 case 8: 365 v=rzx; << 322 v=rzx; 366 break; << 323 break; 367 case 9: << 324 case 9: 368 v=rzy; << 325 v=rzy; 369 break; << 326 break; 370 case 10: << 327 case 10: 371 v=rzz; << 328 v=rzz; 372 break; << 329 break; 373 case 12: << 330 case 12: 374 v=tx; << 331 v=tx; 375 break; << 332 break; 376 case 13: << 333 case 13: 377 v=ty; << 334 v=ty; 378 break; << 335 break; 379 case 14: << 336 case 14: 380 v=tz; << 337 v=tz; 381 break; << 338 break; 382 case 3: << 339 case 3: 383 case 7: << 340 case 7: 384 case 11: << 341 case 11: 385 break; << 342 break; 386 case 15: << 343 case 15: 387 v=1.0; << 344 v=1.0; 388 break; << 345 break; 389 } << 346 } 390 return v; << 347 return v; 391 } 348 } 392 349 393 inline 350 inline 394 G4bool G4AffineTransform::IsRotated() const 351 G4bool G4AffineTransform::IsRotated() const 395 { 352 { 396 return !(rxx==1.0 && ryy==1.0 && rzz==1.0); << 353 return (rxx==1.0 && ryy==1.0 && rzz==1.0) ? false : true; 397 } 354 } 398 355 399 inline 356 inline 400 G4bool G4AffineTransform::IsTranslated() const 357 G4bool G4AffineTransform::IsTranslated() const 401 { 358 { 402 return (tx != 0.0) || (ty != 0.0) || (tz != << 359 return (tx || ty || tz) ? true:false; 403 } 360 } 404 361 405 inline G4RotationMatrix G4AffineTransform::Net << 362 inline G4RotationMatrix G4AffineTransform::NetRotation() const { 406 { << 363 G4RotationMatrix m; 407 return G4Rep3x3(rxx,rxy,rxz, << 364 return m.rotateAxes(G4ThreeVector(rxx,ryx,rzx), 408 ryx,ryy,ryz, << 365 G4ThreeVector(rxy,ryy,rzy), 409 rzx,rzy,rzz); << 366 G4ThreeVector(rxz,ryz,rzz)); 410 } << 411 << 412 inline G4RotationMatrix G4AffineTransform::Inv << 413 { << 414 return G4Rep3x3(rxx,ryx,rzx, << 415 rxy,ryy,rzy, << 416 rxz,ryz,rzz); << 417 } 367 } 418 368 419 inline 369 inline 420 G4ThreeVector G4AffineTransform::NetTranslatio 370 G4ThreeVector G4AffineTransform::NetTranslation() const 421 { 371 { 422 return {tx,ty,tz}; << 372 return G4ThreeVector(tx,ty,tz); 423 } << 424 << 425 inline << 426 G4ThreeVector G4AffineTransform::InverseNetTra << 427 { << 428 G4double ttx = -tx, tty = -ty, ttz = -tz; << 429 G4double invtx = ttx*rxx + tty*rxy + ttz*rxz << 430 G4double invty = ttx*ryx + tty*ryy + ttz*ryz << 431 G4double invtz = ttx*rzx + tty*rzy + ttz*rzz << 432 return {invtx,invty,invtz}; << 433 } 373 } 434 374 435 inline 375 inline 436 void G4AffineTransform::SetNetRotation(const G 376 void G4AffineTransform::SetNetRotation(const G4RotationMatrix& rot) 437 { 377 { 438 rxx=rot.xx(); << 378 rxx=rot.xx(); 439 rxy=rot.xy(); << 379 rxy=rot.xy(); 440 rxz=rot.xz(); << 380 rxz=rot.xz(); 441 ryx=rot.yx(); << 381 ryx=rot.yx(); 442 ryy=rot.yy(); << 382 ryy=rot.yy(); 443 ryz=rot.yz(); << 383 ryz=rot.yz(); 444 rzx=rot.zx(); << 384 rzx=rot.zx(); 445 rzy=rot.zy(); << 385 rzy=rot.zy(); 446 rzz=rot.zz(); << 386 rzz=rot.zz(); 447 } 387 } 448 388 449 inline 389 inline 450 void G4AffineTransform::SetNetTranslation(cons 390 void G4AffineTransform::SetNetTranslation(const G4ThreeVector& tlate) 451 { 391 { 452 tx=tlate.x(); << 392 tx=tlate.x(); 453 ty=tlate.y(); << 393 ty=tlate.y(); 454 tz=tlate.z(); << 394 tz=tlate.z(); 455 } << 456 << 457 inline << 458 G4AffineTransform::operator G4Transform3D () c << 459 { << 460 return G4Transform3D(NetRotation().inverse() << 461 } << 462 << 463 inline << 464 std::ostream& operator << (std::ostream& os, c << 465 { << 466 std::streamsize oldPrec = os.precision(6); << 467 G4double DeviationTolerance = 1.0e-05; << 468 << 469 G4double diagDeviation = 0.0; << 470 G4double offdDeviationUL = 0.0; << 471 G4double offdDeviationDR = 0.0; << 472 G4double offdDeviation = 0.0; << 473 << 474 os << " Transformation: " << G4endl; << 475 << 476 // double a = std::max ( 1, 2, 3 ) ; << 477 << 478 G4bool UnitTr = ! transf.IsRotated(); << 479 diagDeviation = std::max( std::fabs( transf[ << 480 std::fabs( transf[ << 481 diagDeviation = std::max( diagDeviation, << 482 std::fabs( transf[ << 483 << 484 offdDeviationUL = std::max( std::fabs( trans << 485 std::fabs( trans << 486 offdDeviationUL = std::max( offdDeviationUL, << 487 std::fabs( trans << 488 << 489 offdDeviationDR = std::max( std::fabs( trans << 490 std::fabs( trans << 491 offdDeviationDR = std::max( offdDeviationDR, << 492 std::fabs( trans << 493 offdDeviation = std::max( offdDeviationUL, o << 494 << 495 if( UnitTr || std::max(diagDeviation, offdDe << 496 { << 497 os << " UNIT Rotation " << G4endl; << 498 } << 499 else << 500 { << 501 os << "rx/x,y,z: " << 502 << transf[0] << " " << transf[1] << " << 503 << "ry/x,y,z: " << 504 << transf[4] << " " << transf[5] << " << 505 << "rz/x,y,z: " << 506 << transf[8] << " " << transf[9] << " << 507 } << 508 << 509 os << "tr/x,y,z: " << transf[12] << " " << << 510 << G4endl; << 511 << 512 os.precision(oldPrec); << 513 << 514 return os; << 515 } 395 } 516 396