// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // Test file for the class G4IntersectionSolid // // #include #include #include "globals.hh" #include "geomdefs.hh" #include "ApproxEqual.hh" #include "G4ThreeVector.hh" #include "G4RotationMatrix.hh" #include "G4AffineTransform.hh" #include "G4VoxelLimits.hh" #include "G4Box.hh" #include "G4Cons.hh" #include "G4Para.hh" #include "G4Sphere.hh" #include "G4Torus.hh" #include "G4Trap.hh" #include "G4Trd.hh" #include "G4Tubs.hh" #include "G4IntersectionSolid.hh" // #include "G4DisplacedSolid.hh" int main() { G4ThreeVector pzero(0,0,0), p; G4ThreeVector ponxside(20,0,0),ponyside(0,30,0),ponzside(0,0,40), ponb2x(10,0,0),ponb2y(0,10,0),ponb2z(0,0,10), ponb2mx(-10,0,0),ponb2my(0,-10,0),ponb2mz(0,0,-10); G4ThreeVector ponmxside(-20,0,0),ponmyside(0,-30,0),ponmzside(0,0,-40); G4ThreeVector ponzsidey(0,25,40),ponmzsidey(0,25,-40), ponb2zy(0,5,10),ponb2mzy(0,5,-10) ; G4ThreeVector pbigx(100,0,0),pbigy(0,100,0),pbigz(0,0,100); G4ThreeVector pbigmx(-100,0,0),pbigmy(0,-100,0),pbigmz(0,0,-100); G4ThreeVector vx(1,0,0),vy(0,1,0),vz(0,0,1); G4ThreeVector vmx(-1,0,0),vmy(0,-1,0),vmz(0,0,-1); G4ThreeVector vxy(1/std::sqrt(2.0),1/std::sqrt(2.0),0); G4ThreeVector vmxy(-1/std::sqrt(2.0),1/std::sqrt(2.0),0); G4ThreeVector vmxmy(-1/std::sqrt(2.0),-1/std::sqrt(2.0),0); G4ThreeVector vxmy(1/std::sqrt(2.0),-1/std::sqrt(2.0),0); G4ThreeVector vxmz(1/std::sqrt(2.0),0,-1/std::sqrt(2.0)); G4double dist; G4int i; G4ThreeVector *pNorm,norm; G4bool *pgoodNorm,goodNorm,calcNorm=true; pNorm=&norm; pgoodNorm=&goodNorm; G4RotationMatrix identity, xRot ; // NOTE: xRot = rotation such that x axis->y axis & y axis->-x axis xRot.rotateZ(-pi*0.5) ; G4Transform3D transform(xRot,ponb2y) ; G4Box b1("Test Box #1",20,30,40); G4Box b2("Test Box #2",10,10,10); G4Tubs t1("Solid Tube #1",0,50,50,0,360); G4Tubs t2("Hole Tube #2",45,50,50,0,360); G4Cons c1("Hollow Full Tube",50,100,50,100,50,0,2*pi) ; G4Cons c2("Full Cone",0,50,0,100,50,0,2*pi) ; G4Tubs* tube3 = new G4Tubs( "OuterFrame", 1.0*m, 1.1*m, 0.50*m, 0*deg, 180*deg ); G4Tubs* tube4 = new G4Tubs("AnotherTubs", 1.0*m, 1.1*m, 0.50*m, 0*deg, 180*deg ); G4RotationMatrix rotmat2; rotmat2.rotateY(pi/4.0); G4Transform3D tran2 = G4Transform3D(rotmat2,G4ThreeVector(0.0,0.0,0.0)); G4VSolid* t3It4 = new G4IntersectionSolid( "Example", tube3, tube4, tran2 ); G4IntersectionSolid b1Ib2("b1Intersectionb2",&b1,&b2,transform) ; G4IntersectionSolid likeb2("b1Intersectionb2",&b1,&b2) ; G4IntersectionSolid nextb2("b2Intersectionb1",&b2,&b1) ; G4IntersectionSolid t1Ib2("t1Intersectionb2",&t1,&b2,&xRot,ponb2y) ; G4IntersectionSolid c2Ib2("c2Intersectionb2",&c2,&b2,transform) ; G4cout.precision(16); // Check Inside assert(b1Ib2.Inside(pzero)==kSurface); assert(b1Ib2.Inside(pbigz)==kOutside); assert(b1Ib2.Inside(ponb2y)==kInside); assert(t1Ib2.Inside(pzero)==kSurface); assert(t1Ib2.Inside(pbigz)==kOutside); assert(t1Ib2.Inside(ponb2y)==kInside); assert(c2Ib2.Inside(pzero)==kSurface); assert(c2Ib2.Inside(pbigz)==kOutside); assert(c2Ib2.Inside(ponb2y)==kInside); // Check Surface Normal G4ThreeVector normal; /* normal=b1Ib2.SurfaceNormal(G4ThreeVector(10,15,0)); assert(ApproxEqual(normal,G4ThreeVector(1,0,0))); normal=b1Ib2.SurfaceNormal(G4ThreeVector(-10,15,0)); assert(ApproxEqual(normal,G4ThreeVector(-1,0,0))); normal=b1Ib2.SurfaceNormal(pzero); assert(ApproxEqual(normal,G4ThreeVector(0,-1,0))); normal=b1Ib2.SurfaceNormal(G4ThreeVector(0,20,0)); assert(ApproxEqual(normal,G4ThreeVector(0,1,0))); normal=b1Ib2.SurfaceNormal(G4ThreeVector(0,15,10)); assert(ApproxEqual(normal,G4ThreeVector(0,0,1))); normal=b1Ib2.SurfaceNormal(G4ThreeVector(0,15,-10)); assert(ApproxEqual(normal,G4ThreeVector(0,0,-1))); */ // DistanceToOut(P) dist=b1Ib2.DistanceToOut(pzero); assert(ApproxEqual(dist,0)); dist=b1Ib2.DistanceToOut(vx); assert(ApproxEqual(dist,0)); dist=b1Ib2.DistanceToOut(vy); assert(ApproxEqual(dist,1)); dist=b1Ib2.DistanceToOut(vz); assert(ApproxEqual(dist,0)); // DistanceToOut(P,V) dist=b1Ib2.DistanceToOut(G4ThreeVector(0,5,0),vx,calcNorm,pgoodNorm,pNorm); assert(ApproxEqual(dist,10)&&ApproxEqual(*pNorm,vx)&&*pgoodNorm); dist=b1Ib2.DistanceToOut(G4ThreeVector(0,5,0),vmx,calcNorm,pgoodNorm,pNorm); assert(ApproxEqual(dist,10)&&ApproxEqual(norm,vmx)&&*pgoodNorm); dist=b1Ib2.DistanceToOut(pzero,vy,calcNorm,pgoodNorm,pNorm); assert(ApproxEqual(dist,20)&&ApproxEqual(norm,vy)&&*pgoodNorm); dist=b1Ib2.DistanceToOut(pzero,vmy,calcNorm,pgoodNorm,pNorm); assert(ApproxEqual(dist,0)&&ApproxEqual(norm,vmy)&&*pgoodNorm); dist=b1Ib2.DistanceToOut(G4ThreeVector(0,5,0),vz,calcNorm,pgoodNorm,pNorm); assert(ApproxEqual(dist,10)&&ApproxEqual(norm,vz)&&*pgoodNorm); dist=b1Ib2.DistanceToOut(G4ThreeVector(0,5,0),vmz,calcNorm,pgoodNorm,pNorm); assert(ApproxEqual(dist,10)&&ApproxEqual(norm,vmz)&&*pgoodNorm); dist=b1Ib2.DistanceToOut(pzero,vxy,calcNorm,pgoodNorm,pNorm); assert(ApproxEqual(dist,std::sqrt(200.0))&&*pgoodNorm); dist=b1Ib2.DistanceToOut(G4ThreeVector(10,5,0),vx,calcNorm,pgoodNorm,pNorm); assert(ApproxEqual(dist,0)&&ApproxEqual(*pNorm,vx)&&*pgoodNorm); dist=b1Ib2.DistanceToOut(ponb2x,vmx,calcNorm,pgoodNorm,pNorm); assert(ApproxEqual(dist,20)&&ApproxEqual(*pNorm,vmx)&&*pgoodNorm); dist=b1.DistanceToOut(ponxside,vy,calcNorm,pgoodNorm,pNorm); // cout<<"b1.DistanceToOut(ponxside,vy) = "<DistanceToIn = "<DistanceToIn( G4ThreeVector(1355.5204683069741804501973092556, -900.36862622234150421718368306756, -85.254645167836457630983204580843), G4ThreeVector(-0.25623628694138916861433585836494, 0.84905863423851268834141592378728, 0.46199826934689036672665451987996)); // assert(ApproxEqual(dist,940.603760037514)); assert(ApproxEqual(dist,kInfinity)); // G4cout<<"t3It4->DistanceToIn = "<