00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include "G4FPlane.hh"
00045 #include "G4SystemOfUnits.hh"
00046 #include "G4CompositeCurve.hh"
00047
00048
00049 G4FPlane::G4FPlane( const G4Vector3D& direction,
00050 const G4Vector3D& axis ,
00051 const G4Point3D& Pt0, G4int sense )
00052 : pplace(direction, axis, Pt0), Convex(0), projectedBoundary(0)
00053 {
00054 G4Point3D Pt1 = G4Point3D( Pt0 + direction );
00055
00056
00057
00058 G4Point3D Pt2 = G4Point3D( Pt0 + axis.cross(direction) );
00059
00060 G4Ray::CalcPlane3Pts( Pl, Pt0, Pt1, Pt2 );
00061
00062 active = 1;
00063 sameSense = sense;
00064 CalcNormal();
00065 distance = kInfinity;
00066 Type = 1;
00067 }
00068
00069
00070 G4FPlane::G4FPlane(const G4Point3DVector* pVec,
00071 const G4Point3DVector* iVec,
00072 G4int sense)
00073 : pplace( (*pVec)[0]-(*pVec)[1],
00074 ((*pVec)[pVec->size()-1]-(*pVec)[0])
00075 .cross((*pVec)[0]-(*pVec)[1]),
00076 (*pVec)[0] )
00077
00078 {
00079 G4Ray::CalcPlane3Pts( Pl, (*pVec)[0], (*pVec)[1], (*pVec)[2] );
00080
00081 G4CurveVector bounds;
00082 G4CompositeCurve* polygon;
00083
00084 projectedBoundary = new G4SurfaceBoundary;
00085
00086 sameSense = sense;
00087
00088
00089
00090 polygon= new G4CompositeCurve(*pVec);
00091
00092 for (size_t i=0; i< polygon->GetSegments().size(); i++)
00093 polygon->GetSegments()[i]->SetSameSense(sameSense);
00094
00095 bounds.push_back(polygon);
00096
00097
00098
00099 if (iVec)
00100 {
00101 polygon= new G4CompositeCurve(*iVec);
00102
00103 for (size_t i=0; i< polygon->GetSegments().size(); i++)
00104 polygon->GetSegments()[i]->SetSameSense(sameSense);
00105
00106 bounds.push_back(polygon);
00107 }
00108
00109
00110
00111 for (size_t j=0; j< bounds.size(); j++)
00112 bounds[j]->SetSameSense(sameSense);
00113
00114
00115 SetBoundaries(&bounds);
00116
00117 CalcNormal();
00118 IsConvex();
00119 distance = kInfinity;
00120 Type=1;
00121 }
00122
00123
00124 G4FPlane::~G4FPlane()
00125 {
00126 delete NormalX;
00127 }
00128
00129
00130 void G4FPlane::CalcBBox()
00131 {
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 bbox= new G4BoundingBox3D(surfaceBoundary.BBox().GetBoxMin(),
00142 surfaceBoundary.BBox().GetBoxMax());
00143
00144 }
00145
00146
00147 void G4FPlane::CalcNormal()
00148 {
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 const G4Point3D tmp = pplace.GetLocation();
00178 G4Vector3D norm;
00179 G4int sense = GetSameSense();
00180
00181 if (sense)
00182 norm = pplace.GetAxis();
00183 else
00184 norm = - pplace.GetAxis();
00185
00186 NormalX = new G4Ray(tmp, norm);
00187 NormalX->RayCheck();
00188 NormalX->CreatePlanes();
00189 }
00190
00191
00192 void G4FPlane::Project()
00193 {
00194
00195
00196
00197
00198
00199
00200
00201 }
00202
00203
00204 G4int G4FPlane::IsConvex() const
00205 {
00206 return -1;
00207 }
00208
00209
00210 G4int G4FPlane::Intersect(const G4Ray& rayref)
00211 {
00212
00213
00214
00215
00216
00217 Intersected =1;
00218
00219
00220
00221
00222 hitpoint = PINFINITY;
00223 register G4double a, b, t;
00224
00225 register const G4Vector3D& RayDir = rayref.GetDir();
00226 register const G4Point3D& RayStart = rayref.GetStart();
00227
00228 G4double dirx = RayDir.x();
00229 G4double diry = RayDir.y();
00230 G4double dirz = RayDir.z();
00231
00232 G4Vector3D norm = (*NormalX).GetDir();
00233 G4Point3D srf_point = pplace.GetLocation();
00234
00235 b = norm.x() * dirx + norm.y() * diry + norm.z() * dirz;
00236
00237 if ( std::fabs(b) < perMillion )
00238 {
00239
00240 }
00241 else
00242 {
00243 G4double startx = RayStart.x();
00244 G4double starty = RayStart.y();
00245 G4double startz = RayStart.z();
00246
00247 a = norm.x() * (srf_point.x() - startx) +
00248 norm.y() * (srf_point.y() - starty) +
00249 norm.z() * (srf_point.z() - startz) ;
00250
00251 t = a/b;
00252
00253
00254
00255 G4double solx,soly,solz;
00256 solx = startx + t * dirx;
00257 soly = starty + t * diry;
00258 solz = startz + t * dirz;
00259
00260
00261 if( (t*dirx >= -kCarTolerance/2) && (t*dirx <= kCarTolerance/2) )
00262 solx = startx;
00263
00264 if( (t*diry >= -kCarTolerance/2) && (t*diry <= kCarTolerance/2) )
00265 soly = starty;
00266
00267 if( (t*dirz >= -kCarTolerance/2) && (t*dirz <= kCarTolerance/2) )
00268 solz = startz;
00269
00270 G4bool xhit = (dirx < 0 && solx <= startx) || (dirx >= 0 && solx >= startx);
00271 G4bool yhit = (diry < 0 && soly <= starty) || (diry >= 0 && soly >= starty);
00272 G4bool zhit = (dirz < 0 && solz <= startz) || (dirz >= 0 && solz >= startz);
00273
00274 if( xhit && yhit && zhit ) {
00275 hitpoint= G4Point3D(solx, soly, solz);
00276 }
00277 }
00278
00279
00280 closest_hit = hitpoint;
00281
00282 if(closest_hit.x() == kInfinity)
00283 {
00284
00285 active=0;
00286 SetDistance(kInfinity);
00287 return 0;
00288 }
00289 else
00290 {
00291
00292
00293
00294 SetDistance( RayStart.distance2(closest_hit) );
00295
00296
00297
00298
00299
00300
00301
00302 G4Point3D projectedHit= pplace.GetToPlacementCoordinates() * closest_hit;
00303
00304
00305 G4Ray testRay( projectedHit, G4Vector3D(1, 0.01, 0) );
00306
00307
00308 G4int nbinter = projectedBoundary->IntersectRay2D(testRay);
00309
00310
00311
00312
00313 if(nbinter&1)
00314 {
00315
00316
00317 if(distance <= kCarTolerance*0.5*kCarTolerance*0.5)
00318 {
00319
00320 SetDistance(0);
00321 }
00322 else
00323 {
00324
00325 }
00326
00327 return 1 ;
00328 }
00329 else
00330 {
00331
00332
00333 active=0;
00334 SetDistance(kInfinity);
00335 return 0;
00336 }
00337 }
00338 }
00339
00340
00341 G4double G4FPlane::ClosestDistanceToPoint(const G4Point3D& Pt)
00342 {
00343
00344
00345
00346 G4double dist = Pt.x()*Pl.a + Pt.y()*Pl.b + Pt.z()*Pl.c - Pl.d;
00347
00348 return dist;
00349 }
00350
00351
00352 void G4FPlane::InitBounded()
00353 {
00354
00355
00356 projectedBoundary =
00357 surfaceBoundary.Project( pplace.GetToPlacementCoordinates() );
00358 }
00359
00360 G4double G4FPlane::HowNear( const G4Vector3D& Pt ) const
00361 {
00362 G4double hownear = Pt.x()*Pl.a + Pt.y()*Pl.b + Pt.z()*Pl.c - Pl.d;
00363
00364 return hownear;
00365 }