G4Ray Class Reference

#include <G4Ray.hh>


Public Member Functions

 G4Ray ()
 G4Ray (const G4Point3D &start0, const G4Vector3D &dir0)
 ~G4Ray ()
G4Point3D GetPoint (G4double i) const
G4double GetPPoint (const G4Point3D &p) const
const G4Vector3DGetDir () const
const G4Point3DGetStart () const
void SetDir (const G4Vector3D &dir0)
void SetStart (const G4Point3D &start0)
const G4PlaneGetPlane (G4int number_of_plane) const
void RayCheck ()
void CreatePlanes ()
G4double P2 (G4double x) const
G4int NearZero (G4double val, G4double epsilon) const
void MatVecOrtho (register G4Vector3D &out, register const G4Vector3D &in)
void Vsetall (G4Vector3D &a, G4double s)
void Init (const G4Point3D &start0, const G4Vector3D &dir0)

Static Public Member Functions

static G4int CalcPlane3Pts (G4Plane &plane, const G4Point3D &a, const G4Point3D &b, const G4Point3D &c)
static void Vcross (G4Plane &a, const G4Vector3D &b, const G4Vector3D &c)
static void Vcross (G4Vector3D &a, const G4Vector3D &b, const G4Vector3D &c)
static void Vmove (G4Point3D &a, const G4Point3D &b)
static void Vadd2 (G4Point3D &a, const G4Point3D &b, const G4Vector3D &c)
static void Vsub2 (G4Vector3D &a, const G4Point3D &b, const G4Point3D &c)
static void Vscale (G4Plane &a, const G4Plane &b, G4double c)
static G4double Vdot (const G4Plane &a, const G4Point3D &b)
static G4double Magsq (const G4Plane &a)
static G4double Magnitude (const G4Plane &a)


Detailed Description

Definition at line 48 of file G4Ray.hh.


Constructor & Destructor Documentation

G4Ray::G4Ray (  ) 

Definition at line 39 of file G4Ray.cc.

00040   : r_min(0.), r_max(0.)
00041 {
00042 }

G4Ray::G4Ray ( const G4Point3D start0,
const G4Vector3D dir0 
)

Definition at line 44 of file G4Ray.cc.

References Init().

00045 {
00046   Init(start0, dir0);
00047 }

G4Ray::~G4Ray (  ) 

Definition at line 49 of file G4Ray.cc.

00050 {
00051 }


Member Function Documentation

G4int G4Ray::CalcPlane3Pts ( G4Plane plane,
const G4Point3D a,
const G4Point3D b,
const G4Point3D c 
) [static]

Definition at line 212 of file G4Ray.cc.

References G4Plane::d, Magnitude(), SQRT_SMALL_FASTF, Vcross(), Vdot(), Vscale(), and Vsub2().

Referenced by CreatePlanes(), and G4FPlane::G4FPlane().

00216 {
00217   // Creates the two orthogonal planes which are needed in projecting the
00218   // surface into 2D.
00219 
00220   G4Vector3D    B_A;
00221   G4Vector3D    C_A;
00222   G4Vector3D    C_B;
00223   
00224   register G4double mag;
00225 
00226   Vsub2( B_A, b, a );
00227   Vsub2( C_A, c, a );
00228   Vsub2( C_B, c, b );
00229 
00230   Vcross( plane1, B_A, C_A );
00231 
00232   //    Ensure unit length Normal 
00233   mag = Magnitude(plane1);
00234   if( mag  <= SQRT_SMALL_FASTF )
00235   {
00236     return(-1);//        FAIL 
00237   }
00238   
00239   mag = 1/mag;
00240   
00241   G4Plane pl2(plane1);
00242   Vscale( plane1, pl2, mag );
00243 
00244   //     Find distance from the origin to the G4Plane 
00245   plane1.d = Vdot( plane1, a );
00246   
00247   return(0);    //ok
00248 }

void G4Ray::CreatePlanes (  ) 

Definition at line 63 of file G4Ray.cc.

References CalcPlane3Pts(), MatVecOrtho(), NearZero(), PINFINITY(), SQRT_SMALL_FASTF, Vadd2(), Vcross(), and Vmove().

Referenced by G4FPlane::CalcNormal(), and Init().

00064 {
00065   // Creates two orthogonal planes(plane1,plane2) the ray (rray) 
00066   // situated in the intersection of the planes. The planes are 
00067   // used to project the surface (nurb) in two dimensions.
00068   
00069   G4Vector3D RayDir    = dir;
00070   G4Point3D  RayOrigin = start;
00071 
00072   G4Point3D  p1, p2, p3, p4;
00073   G4Vector3D dir1, dir2;
00074   G4Vector3D invdir = G4Vector3D( PINFINITY );
00075   
00076   if(!NearZero(RayDir.x(), SQRT_SMALL_FASTF)) 
00077     { invdir.setX(1.0 / RayDir.x()); }
00078     
00079   if(!NearZero(RayDir.y(), SQRT_SMALL_FASTF)) 
00080     { invdir.setY(1.0 / RayDir.y()); }
00081     
00082   if(!NearZero(RayDir.z(), SQRT_SMALL_FASTF)) 
00083     { invdir.setZ(1.0 / RayDir.z()); }
00084 
00085   MatVecOrtho(dir1, RayDir);
00086   
00087   Vcross( dir2, RayDir, dir1);
00088   Vmove(p1, RayOrigin);
00089   Vadd2(p2, RayOrigin, RayDir);
00090   Vadd2(p3, RayOrigin, dir1);
00091   Vadd2(p4, RayOrigin, dir2);
00092 
00093   CalcPlane3Pts( plane1, p1, p3, p2);
00094   CalcPlane3Pts( plane2, p1, p2, p4);
00095 }

const G4Vector3D & G4Ray::GetDir (  )  const [inline]

Definition at line 51 of file G4Ray.icc.

Referenced by G4ToroidalSurface::Intersect(), G4SphericalSurface::Intersect(), G4FPlane::Intersect(), G4FCylindricalSurface::Intersect(), G4FConicalSurface::Intersect(), G4CylindricalSurface::Intersect(), G4ConicalSurface::Intersect(), G4Parabola::IntersectRay2D(), G4Line::IntersectRay2D(), G4Hyperbola::IntersectRay2D(), G4Ellipse::IntersectRay2D(), G4BREPSolid::IsConvex(), G4FPlane::SurfaceNormal(), and G4BoundingBox3D::Test().

00052 {
00053   return dir;
00054 }

const G4Plane & G4Ray::GetPlane ( G4int  number_of_plane  )  const

Definition at line 54 of file G4Ray.cc.

00055 {
00056   if(number_of_plane==1)
00057     { return plane2; }
00058   else
00059     { return plane1; }
00060 }

G4Point3D G4Ray::GetPoint ( G4double  i  )  const [inline]

Definition at line 38 of file G4Ray.icc.

Referenced by G4CurveRayIntersection::GetPoint(), G4CurveRayIntersection::GetPPoint(), G4SphericalSurface::Intersect(), G4CylindricalSurface::Intersect(), and G4ConicalSurface::Intersect().

00039 {
00040   return G4Point3D( start+i*dir );
00041 }

G4double G4Ray::GetPPoint ( const G4Point3D p  )  const [inline]

Definition at line 44 of file G4Ray.icc.

Referenced by G4CurveRayIntersection::GetDistance().

00045 {
00046   // |dir|==1
00047   return (p-start)*dir;
00048 }

const G4Point3D & G4Ray::GetStart (  )  const [inline]

Definition at line 57 of file G4Ray.icc.

Referenced by G4ToroidalSurface::Intersect(), G4SphericalSurface::Intersect(), G4FPlane::Intersect(), G4FCylindricalSurface::Intersect(), G4FConicalSurface::Intersect(), G4CylindricalSurface::Intersect(), G4ConicalSurface::Intersect(), G4Parabola::IntersectRay2D(), G4Line::IntersectRay2D(), G4Hyperbola::IntersectRay2D(), G4Ellipse::IntersectRay2D(), and G4BoundingBox3D::Test().

00058 {
00059   return start;
00060 }

void G4Ray::Init ( const G4Point3D start0,
const G4Vector3D dir0 
) [inline]

Definition at line 75 of file G4Ray.icc.

References CreatePlanes(), and RayCheck().

Referenced by G4Ray().

00076 {
00077   start= start0;
00078   dir=   dir0;
00079   RayCheck();
00080   CreatePlanes();
00081 }

G4double G4Ray::Magnitude ( const G4Plane a  )  [static]

Definition at line 329 of file G4Ray.cc.

References Magsq().

Referenced by CalcPlane3Pts().

00330 {
00331   return (std::sqrt( Magsq( a )) );
00332 }

G4double G4Ray::Magsq ( const G4Plane a  )  [static]

Definition at line 323 of file G4Ray.cc.

References G4Plane::a, G4Plane::b, and G4Plane::c.

Referenced by Magnitude().

00324 {
00325   return ( a.a * a.a + a.b * a.b + a.c *a.c );
00326 }

void G4Ray::MatVecOrtho ( register G4Vector3D out,
register const G4Vector3D in 
)

Definition at line 98 of file G4Ray.cc.

References NearZero(), SMALL, and Vsetall().

Referenced by CreatePlanes().

00100 {
00101   register G4double f;
00102   G4int             i_Which;
00103 
00104   if( NearZero(in.x(), 0.0001)
00105    && NearZero(in.y(), 0.0001)
00106    && NearZero(in.z(), 0.0001) )  
00107   {
00108     Vsetall( out, 0 );
00109     return;
00110   }
00111  
00112   //      Find component closest to zero 
00113   f = std::fabs(in.x());
00114   i_Which=0;
00115   
00116   if( std::fabs(in.y()) < f )
00117   {
00118     f = std::fabs(in.y());
00119     i_Which=1;
00120   }
00121   
00122   if( std::fabs(in.z()) < f )
00123   {
00124     i_Which=2;
00125   }
00126   
00127   if(!i_Which)
00128   {
00129     f = std::sqrt((in.y())*(in.y())+(in.z())*(in.z()));    // hypot(in.y(),in.z())
00130   }
00131   else
00132   {
00133     if(i_Which==1)
00134     {
00135       f = std::sqrt((in.z())*(in.z())+(in.x())*(in.x()));  // hypot(in.z(),in.x())
00136     }
00137     else
00138     {
00139       f = std::sqrt((in.x())*(in.x())+(in.y())*(in.y()));  // hypot(in.x(),in.y())
00140     }
00141   }
00142   if( NearZero( f, SMALL ) )
00143   {
00144     Vsetall( out, 0 );
00145     return;
00146   }
00147     
00148   f = 1.0/f;
00149     
00150   if(!i_Which)
00151   {
00152     out.setX(0.0);
00153     out.setY(-in.z()*f);
00154     out.setZ( in.y()*f);
00155   }
00156   else
00157   {
00158     if(i_Which==1)
00159     {
00160       out.setY(0.0);
00161       out.setZ(-in.x()*f);
00162       out.setX( in.y()*f);
00163     }
00164     else
00165     {
00166       out.setZ(0.0);
00167       out.setX(-in.z()*f);
00168       out.setY( in.y()*f);
00169     }
00170   }
00171 } 

G4int G4Ray::NearZero ( G4double  val,
G4double  epsilon 
) const [inline]

Definition at line 90 of file G4Ray.icc.

Referenced by CreatePlanes(), and MatVecOrtho().

00091 {
00092   return ( ((val) > -epsilon) && ((val) < epsilon) );
00093 }

G4double G4Ray::P2 ( G4double  x  )  const [inline]

Definition at line 84 of file G4Ray.icc.

00085 {
00086   return(x*x);
00087 }

void G4Ray::RayCheck (  ) 

Definition at line 251 of file G4Ray.cc.

References FatalException, and G4Exception().

Referenced by G4FPlane::CalcNormal(), and Init().

00252 {
00253   // Check that the ray has a G4Vector3D...
00254   if (dir==G4Vector3D(0, 0, 0)) 
00255   {
00256     G4Exception("G4Ray::RayCheck()", "GeomSolids0002", FatalException,
00257                 "Invalid zero direction given !");
00258   }
00259 
00260   // Make sure that the vector is unit length
00261   dir= dir.unit();
00262   r_min = 0;
00263   r_max = 0;
00264 }

void G4Ray::SetDir ( const G4Vector3D dir0  )  [inline]

Definition at line 63 of file G4Ray.icc.

00064 {
00065   dir= dir0.unit();
00066 }

void G4Ray::SetStart ( const G4Point3D start0  )  [inline]

Definition at line 69 of file G4Ray.icc.

00070 {
00071   start= start0;
00072 }

void G4Ray::Vadd2 ( G4Point3D a,
const G4Point3D b,
const G4Vector3D c 
) [static]

Definition at line 291 of file G4Ray.cc.

Referenced by CreatePlanes().

00292 {
00293   a.setX(b.x() + c.x()) ;
00294   a.setY(b.y() + c.y()) ;
00295   a.setZ(b.z() + c.z()) ;
00296 }       

void G4Ray::Vcross ( G4Vector3D a,
const G4Vector3D b,
const G4Vector3D c 
) [static]

Definition at line 275 of file G4Ray.cc.

00276 { 
00277   a.setX(b.y()  * c.z()  - b.z()  * c.y()) ;
00278   a.setY(b.z()  * c.x()  - b.x()  * c.z()) ;
00279   a.setZ(b.x()  * c.y()  - b.y()  * c.x()) ;
00280 }

void G4Ray::Vcross ( G4Plane a,
const G4Vector3D b,
const G4Vector3D c 
) [static]

Definition at line 267 of file G4Ray.cc.

References G4Plane::a, G4Plane::b, and G4Plane::c.

Referenced by CalcPlane3Pts(), and CreatePlanes().

00268 { 
00269   a.a = b.y()  * c.z()  - b.z()  * c.y() ;
00270   a.b = b.z()  * c.x()  - b.x()  * c.z() ;
00271   a.c = b.x()  * c.y()  - b.y()  * c.x() ;
00272 }

G4double G4Ray::Vdot ( const G4Plane a,
const G4Point3D b 
) [static]

Definition at line 315 of file G4Ray.cc.

References G4Plane::a, G4Plane::b, and G4Plane::c.

Referenced by CalcPlane3Pts().

00316 {
00317   return (a.a * b.x() + 
00318           a.b * b.y() + 
00319           a.c * b.z());
00320 }

void G4Ray::Vmove ( G4Point3D a,
const G4Point3D b 
) [static]

Definition at line 283 of file G4Ray.cc.

Referenced by CreatePlanes().

00284 { 
00285   a.setX(b.x());
00286   a.setY(b.y());
00287   a.setZ(b.z());
00288 }

void G4Ray::Vscale ( G4Plane a,
const G4Plane b,
G4double  c 
) [static]

Definition at line 307 of file G4Ray.cc.

References G4Plane::a, G4Plane::b, and G4Plane::c.

Referenced by CalcPlane3Pts().

00308 { 
00309   a.a = b.a * c;
00310   a.b = b.b * c;
00311   a.c = b.c * c;
00312 }

void G4Ray::Vsetall ( G4Vector3D a,
G4double  s 
) [inline]

Definition at line 96 of file G4Ray.icc.

Referenced by MatVecOrtho().

00097 {
00098   a.setX(i); a.setY(i); a.setZ(i);
00099 }

void G4Ray::Vsub2 ( G4Vector3D a,
const G4Point3D b,
const G4Point3D c 
) [static]

Definition at line 299 of file G4Ray.cc.

Referenced by CalcPlane3Pts().

00300 {
00301   a.setX(b.x() - c.x());
00302   a.setY(b.y() - c.y());
00303   a.setZ(b.z() - c.z());
00304 }


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:53:15 2013 for Geant4 by  doxygen 1.4.7