54 const G4int handedness,
65 axis0min, axis1min, axis0max, axis1max),
66 fKappa(kappa), fTanStereo(tanstereo),
67 fTan2Stereo(tanstereo*tanstereo), fR0(r0), fR02(r0*r0), fDPhi(
twopi)
71 G4Exception(
"G4TwistTubsHypeSide::G4TwistTubsHypeSide()",
73 "Should swap axis0 and axis1!");
76 fInside.gp.set(kInfinity, kInfinity, kInfinity);
110 if (handedness < 0) {
111 fTanStereo = TanInnerStereo;
114 fTanStereo = TanOuterStereo;
117 fTan2Stereo = fTanStereo * fTanStereo;
123 fInside.gp.set(kInfinity, kInfinity, kInfinity);
126 SetCorners(EndInnerRadius, EndOuterRadius, DPhi, EndPhi, EndZ) ;
136 fR0(0.), fR02(0.), fDPhi(0.)
175 normal = normal.unit();
194 if (fInside.gp == gp) {
195 return fInside.inside;
204 return fInside.inside;
211 if (distanceToOut < -halftol) {
217 G4int areacode = GetAreaCode(p);
223 if (distanceToOut <= halftol) {
229 G4cout <<
"WARNING - G4TwistTubsHypeSide::Inside()" <<
G4endl
230 <<
" Invalid option !" <<
G4endl
231 <<
" name, areacode, distanceToOut = "
232 <<
GetName() <<
", " << std::hex << areacode << std::dec <<
", "
233 << distanceToOut <<
G4endl;
237 return fInside.inside;
302 for (i=0; i<2; i++) {
303 distance[i] = kInfinity;
306 gxx[i].
set(kInfinity, kInfinity, kInfinity);
335 if (vrho == 0 || (vrho/absvz) <= (absvz*std::fabs(fTanStereo)/absvz)) {
337 distance[0] = kInfinity;
339 isvalid[0], 0, validate, &gp, &gv);
344 G4double xxz = std::sqrt(fR02 / (vslope2 - fTan2Stereo))
345 * (vz / std::fabs(vz)) ;
347 xx[0].
set(t*v.
x(), t*v.
y(), xxz);
350 xx[0].
set(v.
x()*fR0, v.
y()*fR0, 0);
352 distance[0] = xx[0].
mag();
356 areacode[0] = GetAreaCode(xx[0]);
358 if (distance[0] >= 0) isvalid[0] =
true;
361 areacode[0] = GetAreaCode(xx[0],
false);
363 if (distance[0] >= 0) isvalid[0] =
true;
367 if (distance[0] >= 0) isvalid[0] =
true;
371 isvalid[0], 1, validate, &gp, &gv);
380 G4double b = 2.0 * ( p.
x() * v.
x() + p.
y() * v.
y() - p.
z() * v.
z() * fTan2Stereo );
381 G4double c = p.
x()*p.
x() + p.
y()*p.
y() - fR02 - p.
z()*p.
z()*fTan2Stereo;
389 xx[0] = p + distance[0]*
v;
393 areacode[0] = GetAreaCode(xx[0]);
395 if (distance[0] >= 0) isvalid[0] =
true;
398 areacode[0] = GetAreaCode(xx[0],
false);
400 if (distance[0] >= 0) isvalid[0] =
true;
404 if (distance[0] >= 0) isvalid[0] =
true;
408 isvalid[0], 1, validate, &gp, &gv);
417 isvalid[0], 0, validate, &gp, &gv);
426 G4double tmpdist[2] = {kInfinity, kInfinity};
429 G4bool tmpisvalid[2] = {
false,
false};
432 for (i=0; i<2; i++) {
433 tmpdist[i] = factor*(-b - D);
435 tmpxx[i] = p + tmpdist[i]*
v;
438 tmpareacode[i] = GetAreaCode(tmpxx[i]);
440 if (tmpdist[i] >= 0) tmpisvalid[i] =
true;
444 tmpareacode[i] = GetAreaCode(tmpxx[i],
false);
446 if (tmpdist[i] >= 0) tmpisvalid[i] =
true;
451 if (tmpdist[i] >= 0) tmpisvalid[i] =
true;
456 if (tmpdist[0] <= tmpdist[1]) {
457 distance[0] = tmpdist[0];
458 distance[1] = tmpdist[1];
463 areacode[0] = tmpareacode[0];
464 areacode[1] = tmpareacode[1];
465 isvalid[0] = tmpisvalid[0];
466 isvalid[1] = tmpisvalid[1];
468 distance[0] = tmpdist[1];
469 distance[1] = tmpdist[0];
474 areacode[0] = tmpareacode[1];
475 areacode[1] = tmpareacode[0];
476 isvalid[0] = tmpisvalid[1];
477 isvalid[1] = tmpisvalid[0];
481 isvalid[0], 2, validate, &gp, &gv);
483 isvalid[1], 2, validate, &gp, &gv);
491 isvalid[0], 0, validate, &gp, &gv);
528 for (
G4int i=0; i<2; i++) {
529 distance[i] = kInfinity;
531 gxx[i].
set(kInfinity, kInfinity, kInfinity);
544 for (
G4int i=0; i<2; i++) {
548 if ((gp - lastgxx[0]).mag() < halftol || (gp - lastgxx[1]).mag() < halftol) {
567 G4double r1 = std::sqrt(fR02 + pz * pz * fTan2Stereo);
571 if (prho > r1 + halftol) {
578 G4double z2 = (prho * fTanStereo + pz) / (1 + fTan2Stereo);
579 G4double r2 = std::sqrt(fR02 + z2 * z2 * fTan2Stereo);
587 distance[0] = (pabsz - xx1).mag();
593 }
else if (prho < r1 - halftol) {
599 xx1.
set(r1, 0. , pz);
602 xx1.
set(t * pabsz.x(), t * pabsz.y() , pz);
617 xx2.
set(r2, 0. , 0.);
620 xx2.
set(t * pabsz.x(), t * pabsz.y() , 0.);
629 xx.
set(p.
x(), p.
y(), pz);
662 G4int phiareacode = GetAreaCodeInPhi(xx);
667 if ((phiareacode &
sAxisMin) == sAxisMin) {
670 if (isoutsideinphi) isoutside =
true;
675 if (isoutsideinphi) isoutside =
true;
687 if (xx.
z() <=
fAxisMin[zaxis] - ctol) isoutside =
true;
689 }
else if (xx.
z() >
fAxisMax[zaxis] - ctol) {
692 if (areacode & sBoundary) areacode |=
sCorner;
695 if (xx.
z() >=
fAxisMax[zaxis] + ctol) isoutside =
true;
703 areacode = tmpareacode;
704 }
else if ((areacode & sBoundary) !=
sBoundary) {
712 G4int phiareacode = GetAreaCodeInPhi(xx,
false);
728 if (phiareacode == sAxisMin) {
731 if (areacode & sBoundary) areacode |=
sCorner;
734 }
else if (phiareacode == sAxisMax) {
737 if (areacode & sBoundary) areacode |=
sCorner;
744 if ((areacode & sBoundary) !=
sBoundary) {
750 std::ostringstream message;
751 message <<
"Feature NOT implemented !" <<
G4endl
753 <<
" fAxis[1] = " <<
fAxis[1];
790 areacode = tmpareacode;
810 void G4TwistTubsHypeSide::SetCorners(
826 for (i=0; i<2; i++) {
828 : EndInnerRadius[i]);
837 x = endRad[zmin]*std::cos(endPhi[zmin] - halfdphi);
838 y = endRad[zmin]*std::sin(endPhi[zmin] - halfdphi);
843 x = endRad[zmin]*std::cos(endPhi[zmin] + halfdphi);
844 y = endRad[zmin]*std::sin(endPhi[zmin] + halfdphi);
849 x = endRad[zmax]*std::cos(endPhi[zmax] + halfdphi);
850 y = endRad[zmax]*std::sin(endPhi[zmax] + halfdphi);
855 x = endRad[zmax]*std::cos(endPhi[zmax] - halfdphi);
856 y = endRad[zmax]*std::sin(endPhi[zmax] - halfdphi);
861 std::ostringstream message;
862 message <<
"Feature NOT implemented !" <<
G4endl
864 <<
" fAxis[1] = " <<
fAxis[1];
874 void G4TwistTubsHypeSide::SetCorners()
878 "Method NOT implemented !");
884 void G4TwistTubsHypeSide::SetBoundaries()
895 direction = direction.
unit();
901 direction = direction.
unit();
907 direction = direction.
unit();
913 direction = direction.
unit();
917 std::ostringstream message;
918 message <<
"Feature NOT implemented !" <<
G4endl
920 <<
" fAxis[1] = " <<
fAxis[1];
921 G4Exception(
"G4TwistTubsHypeSide::SetBoundaries()",
945 for ( i = 0 ; i<
n ; i++ ) {
949 for ( j = 0 ; j<k ; j++ )
951 nnode =
GetNode(i,j,k,n,iside) ;
957 x = xmin + j*(xmax-xmin)/(k-1) ;
959 x = xmax - j*(xmax-xmin)/(k-1) ;
964 xyz[nnode][0] = p.
x() ;
965 xyz[nnode][1] = p.
y() ;
966 xyz[nnode][2] = p.
z() ;
968 if ( i<n-1 && j<k-1 ) {
970 nface =
GetFace(i,j,k,n,iside) ;