51 EGS_BaseShape(Name, f), r_inner(ri), r_outer(ro), hemisphere(hemisph), half_angle(halfangle), xo(Xo) {
52 otype =
"sphericalShell";
69 EGS_Float rad = r_inner + (r_outer - r_inner)*pow(rnd1, 1/3.);
71 EGS_Float cos_max, cos_min;
80 cos_th = cos_min + rnd2*(1 - cos_min);
84 EGS_Float sin_th = sqrt(1-cos_th*cos_th);
86 EGS_Float cos_phi, sin_phi;
89 EGS_Float x = rad*sin_th*cos_phi;
90 EGS_Float y = rad*sin_th*sin_phi;
91 EGS_Float z = rad*cos_th;
93 if (hemisphere != 0) {
94 z = hemisphere*fabs(z);
106 EGS_Float sint = 1-cost*cost;
109 EGS_Float cphi, sphi;
111 sint = r_outer*sqrt(sint);
119 u = (x + this->
xo) - xo;
120 EGS_Float di = 1/u.length();
122 wt = u*x*4*M_PI*r_outer*di*di;
126 return 4*M_PI*r_outer*r_outer;
134 egsWarning(
"createShape(sphericalShell): null input?\n");
139 int err = input->
getInput(
"inner radius", ri);
141 egsWarning(
"createShape(sphericalShell): no 'inner radius' input\n");
145 egsWarning(
"createShape(sphericalShell): 'inner radius' must be >= 0\n");
149 err = input->
getInput(
"outer radius", ro);
151 egsWarning(
"createShape(sphericalShell): no 'outer radius' input\n");
155 egsWarning(
"createShape(sphericalShell): 'outer radius' must be >= 0\n");
159 egsWarning(
"createShape(sphericalShell): 'inner radius' must be less than 'outer radius'\n");
164 err = input->
getInput(
"hemisphere", hemisphere);
168 else if ((hemisphere != 0) && (hemisphere != -1) && (hemisphere != 1)) {
169 egsWarning(
"createShape(sphericalShell): 'hemisphere' must be 1, -1, 0\n");
173 EGS_Float half_angle=0, half_angle_deg= 0;
174 err = input->
getInput(
"half angle", half_angle_deg);
179 half_angle = M_PI/180.*half_angle_deg;
182 if (half_angle && hemisphere) {
183 egsWarning(
"createShape(sphericalShell): Hemisphere and half angle specified! Remove one and try again.");
190 vector<EGS_Float> xo;
191 err = input->
getInput(
"midpoint",xo);
192 if (err || xo.size() != 3) {
Base shape class. All shapes in the EGSnrc C++ class library are derived from EGS_BaseShape.
EGS_AffineTransform * T
The affine transformation attached to the shape.
void setName(EGS_Input *inp)
Set the name of the object from the information provided by inp.
string otype
The object type.
Base random number generator class. All random number generators should be derived from this class.
void getAzimuth(EGS_Float &cphi, EGS_Float &sphi)
Sets cphi and sphi to the cosine and sine of a random angle uniformely distributed between 0 and .
EGS_Float getUniform()
Returns a random number uniformly distributed between zero (inclusive) and 1 (exclusive).
EGS_Float area() const
Returns the sphere surface area.
EGS_SphericalShellShape(EGS_Float ri, EGS_Float ro, int hemisph=0, EGS_Float halfangle=0, const EGS_Vector &Xo=EGS_Vector(0, 0, 0), const string &Name="", EGS_ObjectFactory *f=0)
Construct a sphere of radius r with midpoint Xo.
void getPointSourceDirection(const EGS_Vector &Xo, EGS_RandomGenerator *rndm, EGS_Vector &u, EGS_Float &wt)
Sets the direction u by picking a random point uniformely on the sphere surface.
EGS_Vector xo
The sphere midpoint.
EGS_Vector getPoint(EGS_RandomGenerator *rndm)
Returns a random point within the spherical shell.
EGS_Float sgn
The sphere radius.
EGS_Float half_angle
Half angle of conical section.
A class representing 3D vectors.
Global egspp functions header file.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.