#include <G4ToroidalSurface.hh>
Inheritance diagram for G4ToroidalSurface:
Public Member Functions | |
G4ToroidalSurface () | |
G4ToroidalSurface (const G4Vector3D &, const G4Vector3D &, const G4Vector3D &, G4double, G4double) | |
virtual | ~G4ToroidalSurface () |
G4String | GetEntityType () const |
G4int | Intersect (const G4Ray &) |
void | CalcBBox () |
G4Vector3D | GetDirection () const |
G4Vector3D | GetAxis () const |
G4Point3D | GetLocation () const |
G4double | GetMinRadius () const |
G4double | GetMaxRadius () const |
G4double | ClosestDistanceToPoint (const G4Point3D &x) |
virtual G4Vector3D | SurfaceNormal (const G4Point3D &Pt) const |
void | MultiplyPointByMatrix (G4Point3D &Base) |
void | MultiplyVectorByMatrix (G4Vector3D &DCos) |
Definition at line 46 of file G4ToroidalSurface.hh.
G4ToroidalSurface::G4ToroidalSurface | ( | ) |
G4ToroidalSurface::G4ToroidalSurface | ( | const G4Vector3D & | , | |
const G4Vector3D & | , | |||
const G4Vector3D & | , | |||
G4double | , | |||
G4double | ||||
) |
Definition at line 44 of file G4ToroidalSurface.cc.
References G4Axis2Placement3D::Init().
00049 : EQN_EPS(1e-9) 00050 { 00051 Placement.Init(Dir, Ax, Location); 00052 00053 MinRadius = MinRad; 00054 MaxRadius = MaxRad; 00055 TransMatrix= new G4PointMatrix(4,4); 00056 }
G4ToroidalSurface::~G4ToroidalSurface | ( | ) | [virtual] |
void G4ToroidalSurface::CalcBBox | ( | ) | [virtual] |
Reimplemented from G4Surface.
Definition at line 65 of file G4ToroidalSurface.cc.
References G4Surface::bbox, and G4Axis2Placement3D::GetLocation().
00066 { 00067 // L. Broglia 00068 // G4Point3D Origin = Placement.GetSrfPoint(); 00069 G4Point3D Origin = Placement.GetLocation(); 00070 00071 G4Point3D Min(Origin.x()-MaxRadius, 00072 Origin.y()-MaxRadius, 00073 Origin.z()-MaxRadius); 00074 G4Point3D Max(Origin.x()+MaxRadius, 00075 Origin.y()+MaxRadius, 00076 Origin.z()+MaxRadius); 00077 00078 bbox = new G4BoundingBox3D(Min,Max); 00079 }
Reimplemented from G4Surface.
Definition at line 88 of file G4ToroidalSurface.cc.
References G4Axis2Placement3D::GetLocation().
00089 { 00090 // L. Broglia 00091 // G4Point3D Origin = Placement.GetSrfPoint(); 00092 G4Point3D Origin = Placement.GetLocation(); 00093 00094 G4double Dist = Pt.distance(Origin); 00095 00096 return ((Dist - MaxRadius)*(Dist - MaxRadius)); 00097 }
G4Vector3D G4ToroidalSurface::GetAxis | ( | ) | const [inline] |
Definition at line 50 of file G4ToroidalSurface.icc.
References G4Axis2Placement3D::GetAxis().
00051 { 00052 return Placement.GetAxis(); 00053 }
G4Vector3D G4ToroidalSurface::GetDirection | ( | ) | const [inline] |
Definition at line 44 of file G4ToroidalSurface.icc.
References G4Axis2Placement3D::GetRefDirection().
00045 { 00046 return Placement.GetRefDirection(); 00047 }
G4String G4ToroidalSurface::GetEntityType | ( | ) | const [inline, virtual] |
Reimplemented from G4Surface.
Definition at line 38 of file G4ToroidalSurface.icc.
00039 { 00040 return G4String("Toroidal_Surface"); 00041 }
G4Point3D G4ToroidalSurface::GetLocation | ( | ) | const [inline] |
Definition at line 56 of file G4ToroidalSurface.icc.
References G4Axis2Placement3D::GetLocation().
00057 { 00058 return Placement.GetLocation(); 00059 }
G4double G4ToroidalSurface::GetMaxRadius | ( | ) | const [inline] |
G4double G4ToroidalSurface::GetMinRadius | ( | ) | const [inline] |
Reimplemented from G4Surface.
Definition at line 100 of file G4ToroidalSurface.cc.
References G4Surface::bbox, G4Surface::closest_hit, G4Surface::distance, G4BoundingBox3D::GetBoxMax(), G4BoundingBox3D::GetBoxMin(), G4Ray::GetDir(), G4Ray::GetStart(), and G4Surface::kCarTolerance.
00101 { 00102 // ---- inttor - Intersect a ray with a torus. ------------------------ 00103 // from GraphicsGems II by 00104 00105 // Description: 00106 // Inttor determines the intersection of a ray with a torus. 00107 // 00108 // On entry: 00109 // raybase = The coordinate defining the base of the 00110 // intersecting ray. 00111 // raycos = The G4Vector3D cosines of the above ray. 00112 // center = The center location of the torus. 00113 // radius = The major radius of the torus. 00114 // rplane = The minor radius in the G4Plane of the torus. 00115 // rnorm = The minor radius Normal to the G4Plane of the torus. 00116 // tran = A 4x4 transformation matrix that will position 00117 // the torus at the origin and orient it such that 00118 // the G4Plane of the torus lyes in the x-z G4Plane. 00119 // 00120 // On return: 00121 // nhits = The number of intersections the ray makes with 00122 // the torus. 00123 // rhits = The entering/leaving distances of the 00124 // intersections. 00125 // 00126 // Returns: True if the ray intersects the torus. 00127 // 00128 // -------------------------------------------------------------------- 00129 00130 // Variables. Should be optimized later... 00131 G4Point3D Base = Ray.GetStart(); // Base of the intersection ray 00132 G4Vector3D DCos = Ray.GetDir(); // Direction cosines of the ray 00133 G4int nhits=0; // Number of intersections 00134 G4double rhits[4]; // Intersection distances 00135 G4double hits[4] = {0.,0.,0.,0.}; // Ordered intersection distances 00136 G4double rho, a0, b0; // Related constants 00137 G4double f, l, t, g1, q, m1, u; // Ray dependent terms 00138 G4double C[5]; // Quartic coefficients 00139 00140 // Transform the intersection ray 00141 00142 00143 // MultiplyPointByMatrix (Base); // Matriisi puuttuu viela! 00144 // MultiplyVectorByMatrix (DCos); 00145 00146 // Compute constants related to the torus. 00147 G4double rnorm = MaxRadius - MinRadius; // ei tietoa onko oikein... 00148 rho = MinRadius*MinRadius / (rnorm*rnorm); 00149 a0 = 4. * MaxRadius*MaxRadius; 00150 b0 = MaxRadius*MaxRadius - MinRadius*MinRadius; 00151 00152 // Compute ray dependent terms. 00153 f = 1. - DCos.y()*DCos.y(); 00154 l = 2. * (Base.x()*DCos.x() + Base.z()*DCos.z()); 00155 t = Base.x()*Base.x() + Base.z()*Base.z(); 00156 g1 = f + rho * DCos.y()*DCos.y(); 00157 q = a0 / (g1*g1); 00158 m1 = (l + 2.*rho*DCos.y()*Base.y()) / g1; 00159 u = (t + rho*Base.y()*Base.y() + b0) / g1; 00160 00161 // Compute the coefficients of the quartic. 00162 00163 C[4] = 1.0; 00164 C[3] = 2. * m1; 00165 C[2] = m1*m1 + 2.*u - q*f; 00166 C[1] = 2.*m1*u - q*l; 00167 C[0] = u*u - q*t; 00168 00169 // Use quartic root solver found in "Graphics Gems" by Jochen Schwarze. 00170 nhits = SolveQuartic (C,rhits); 00171 00172 // SolveQuartic returns root pairs in reversed order. 00173 m1 = rhits[0]; u = rhits[1]; rhits[0] = u; rhits[1] = m1; 00174 m1 = rhits[2]; u = rhits[3]; rhits[2] = u; rhits[3] = m1; 00175 00176 // return (*nhits != 0); 00177 00178 if(nhits != 0) 00179 { 00180 // Convert Hit distances to intersection points 00181 /* 00182 G4Point3D** IntersectionPoints = new G4Point3D*[nhits]; 00183 for(G4int a=0;a<nhits;a++) 00184 { 00185 G4double Dist = rhits[a]; 00186 IntersectionPoints[a] = new G4Point3D((Base - Dist * DCos)); 00187 } 00188 // Check wether any of the hits are on the actual surface 00189 // Start with checking for the intersections that are Inside the bbox 00190 00191 G4Point3D* Hit; 00192 G4int InsideBox[2]; // Max 2 intersections on the surface 00193 G4int Counter=0; 00194 */ 00195 00196 G4Point3D BoxMin = bbox->GetBoxMin(); 00197 G4Point3D BoxMax = bbox->GetBoxMax(); 00198 G4Point3D Hit; 00199 G4int c1 = 0; 00200 G4int c2; 00201 G4double tempVec[4]; 00202 00203 for(G4int a=0;a<nhits;a++) 00204 { 00205 while ( (c1 < 4) && (hits[c1] <= rhits[a]) ) 00206 { 00207 tempVec[c1]=hits[c1]; 00208 c1++; 00209 } 00210 00211 for(c2=c1+1;c2<4;c2++) 00212 tempVec[c2]=hits[c2-1]; 00213 00214 if(c1<4) 00215 { 00216 tempVec[c1]=rhits[a]; 00217 00218 for(c2=0;c2<4;c2++) 00219 hits[c2]=tempVec[c2]; 00220 } 00221 } 00222 00223 for(G4int b=0;b<nhits;b++) 00224 { 00225 // Hit = IntersectionPoints[b]; 00226 if(hits[b] >=kCarTolerance*0.5) 00227 { 00228 Hit = Base + (hits[b]*DCos); 00229 // InsideBox[Counter]=b; 00230 if( (Hit.x() > BoxMin.x()) && 00231 (Hit.x() < BoxMax.x()) && 00232 (Hit.y() > BoxMin.y()) && 00233 (Hit.y() < BoxMax.y()) && 00234 (Hit.z() > BoxMin.z()) && 00235 (Hit.z() < BoxMax.z()) ) 00236 { 00237 closest_hit = Hit; 00238 distance = hits[b]*hits[b]; 00239 return 1; 00240 } 00241 00242 // Counter++; 00243 } 00244 } 00245 00246 // If two Inside bbox, find closest 00247 // G4int Closest=0; 00248 00249 // if(Counter>1) 00250 // if(rhits[InsideBox[0]] > rhits[InsideBox[1]]) 00251 // Closest=1; 00252 00253 // Project polygon and do point in polygon 00254 // Projection also for curves etc. 00255 // Should probably be implemented in the curve class. 00256 // G4Plane Plane1 = Ray.GetPlane(1); 00257 // G4Plane Plane2 = Ray.GetPlane(2); 00258 00259 // Point in polygon 00260 return 1; 00261 } 00262 return 0; 00263 }
void G4ToroidalSurface::MultiplyPointByMatrix | ( | G4Point3D & | Base | ) | [inline] |
Definition at line 73 of file G4ToroidalSurface.icc.
References G4PointMatrix::get().
00074 { 00075 Base.setX((Base.x() * TransMatrix->get(0,0)) + 00076 (Base.y() * TransMatrix->get(1,0)) + 00077 (Base.z() * TransMatrix->get(2,0))); 00078 Base.setY((Base.x() * TransMatrix->get(0,1)) + 00079 (Base.y() * TransMatrix->get(1,1)) + 00080 (Base.z() * TransMatrix->get(2,1))); 00081 Base.setZ((Base.x() * TransMatrix->get(0,2)) + 00082 (Base.y() * TransMatrix->get(1,2)) + 00083 (Base.z() * TransMatrix->get(2,2))); 00084 }
void G4ToroidalSurface::MultiplyVectorByMatrix | ( | G4Vector3D & | DCos | ) | [inline] |
Definition at line 87 of file G4ToroidalSurface.icc.
References G4PointMatrix::get().
00088 { 00089 G4double w; 00090 DCos.setX((DCos.x() * TransMatrix->get(0,0)) + 00091 (DCos.y() * TransMatrix->get(1,0)) + 00092 (DCos.z() * TransMatrix->get(2,0)) + TransMatrix->get(3,0)); 00093 00094 DCos.setY((DCos.x() * TransMatrix->get(0,1)) + 00095 (DCos.y() * TransMatrix->get(1,1)) + 00096 (DCos.z() * TransMatrix->get(2,1)) + TransMatrix->get(3,1)); 00097 00098 DCos.setY((DCos.x() * TransMatrix->get(0,2)) + 00099 (DCos.y() * TransMatrix->get(1,2)) + 00100 (DCos.z() * TransMatrix->get(2,2)) + TransMatrix->get(3,2)); 00101 00102 w = ((DCos.x() * TransMatrix->get(0,3)) + 00103 (DCos.y() * TransMatrix->get(1,3)) + 00104 (DCos.z() * TransMatrix->get(2,3)) + TransMatrix->get(3,3)); 00105 00106 if (w != 0.0) 00107 { 00108 DCos.setX(DCos.x() / w); 00109 DCos.setY(DCos.y() / w); 00110 DCos.setZ(DCos.z() / w); 00111 } 00112 }
G4Vector3D G4ToroidalSurface::SurfaceNormal | ( | const G4Point3D & | Pt | ) | const [virtual] |
Implements G4Surface.
Definition at line 82 of file G4ToroidalSurface.cc.
00083 { 00084 return G4Vector3D(0,0,0); 00085 }