27 :
VUSolid(name), fR(r), fCubicVolume(0), fSurfaceArea(0)
29 const double epsilon = 2.e-11;
55 double rad2 = p.
x * p.
x + p.
y * p.
y + p.
z * p.
z;
61 double tolRMax2 = tolRMax * tolRMax;
67 tolRMax2 = tolRMax * tolRMax;
94 const double dRmax = 100.*
fR;
98 rad = sqrt(p.
x * p.
x + p.
y * p.
y + p.
z * p.
z);
99 pDotV3d = p.
x * v.
x + p.
y * v.
y + p.
z * v.
z;
120 c = (rad -
fR) * (rad +
fR);
129 d2 = pDotV3d * pDotV3d - c;
133 s = -pDotV3d - sqrt(d2);
140 double fTerm = s - fmod(s, dRmax);
155 d2 = pDotV3d * pDotV3d - c;
183 ((
UOrb&)*
this).Normal(surfacePoint, normal);
184 double dot = normal.
Dot(v);
185 if (dot > 0)
return 0;
189 double distanceOut =
DistanceToOut(surfacePoint, v, n, convex);
190 return distanceIn + distanceOut;
204 UVector3&
n,
bool& convex,
double )
const
207 bool notOutside =
false;
210 double rad2, pDotV3d;
214 rad2 = p.
x * p.
x + p.
y * p.
y + p.
z * p.
z;
215 pDotV3d = p.
x * v.
x + p.
y * v.
y + p.
z * v.
z;
234 double rad = sqrt(rad2);
238 c = (rad -
fR) * (rad +
fR);
240 if (c < fRTolerance *
fR)
251 d2 = pDotV3d * pDotV3d - c;
253 if ((c > -2 * fRTolerance * fR) &&
254 ((pDotV3d >= 0) || (d2 < 0)))
268 snxt = -pDotV3d + sqrt(d2);
287 cout <<
"Position:" << endl << endl;
288 cout <<
"p.x() = " << p.
x << endl;
289 cout <<
"p.y() = " << p.
y << endl;
290 cout <<
"p.z() = " << p.
z << endl << endl;
291 cout <<
"Rp = " << sqrt(p.
x * p.
x + p.
y * p.
y + p.
z * p.
z) << endl << endl;
292 cout <<
"Direction:" << endl << endl;
293 cout <<
"v.x() = " << v.
x << endl;
294 cout <<
"v.y() = " << v.
y << endl;
295 cout <<
"v.z() = " << v.
z << endl << endl;
296 cout <<
"Proposed distance :" << endl << endl;
297 cout <<
"snxt = " << snxt << endl << endl;
303 Warning, 1,
"Logic error: snxt = kInfinity ???");
311 xi = p.
x + snxt * v.
x;
312 yi = p.
y + snxt * v.
y;
313 zi = p.
z + snxt * v.
z;
322 cout <<
"Position:" << endl << endl;
323 cout <<
"p.x() = " << p.
x <<
" mm" << endl;
324 cout <<
"p.y() = " << p.
y <<
" mm" << endl;
325 cout <<
"p.z() = " << p.
z <<
" mm" << endl << endl;
326 cout <<
"Direction:" << endl << endl;
327 cout <<
"v.x() = " << v.
x << endl;
328 cout <<
"v.y() = " << v.
y << endl;
329 cout <<
"v.z() = " << v.
z << endl << endl;
330 cout <<
"Proposed distance :" << endl << endl;
331 cout <<
"snxt = " << snxt <<
" mm" << endl << endl;
335 UUtils::Exception(
"UOrb::DistanceToOut(p,v,..)",
"Notification",
Warning, 1,
"Undefined side for valid surface normal to solid.");
357 double safe = 0.0,
rad = sqrt(p.
x * p.
x + p.
y * p.
y + p.
z * p.
z);
365 cout <<
"Position:" << endl << endl;
366 cout <<
"p.x = " << p.
x << endl;
367 cout <<
"p.y = " << p.
y << endl;
368 cout <<
"p.z = " << p.
z << endl << endl;
371 "Point p is outside !?");
376 if (safe < 0.) safe = 0.;
396 double rad = sqrt(p.
x * p.
x + p.
y * p.
y + p.
z * p.
z);
423 double rad2 = p.
x * p.
x + p.
y * p.
y + p.
z * p.
z;
424 double rad = sqrt(rad2);
432 bool result = ((rad2 <= tolRMaxP * tolRMaxP) && (rad2 >= tolRMaxM * tolRMaxM));
456 int oldprc = os.precision(16);
457 os <<
"-----------------------------------------------------------\n"
458 <<
" *** Dump for solid - " <<
GetName() <<
" ***\n"
459 <<
" ===================================================\n"
460 <<
" Solid type: UOrb\n"
463 <<
" outer radius: " <<
fR <<
" mm \n"
464 <<
"-----------------------------------------------------------\n";
465 os.precision(oldprc);
479 double cosphi = std::cos(phi);
480 double sinphi = std::sin(phi);
484 double sintheta = std::sqrt(1. -
UUtils::sqr(costheta));
486 return UVector3(
fR * sintheta * cosphi,
fR * sintheta * sinphi,
fR * costheta);
491 return new UOrb(*
this);
497 :
VUSolid(rhs), fR(rhs.fR), fRTolerance(rhs.fRTolerance), fCubicVolume(rhs.fCubicVolume), fSurfaceArea(rhs.fSurfaceArea)
516 VUSolid::operator=(rhs);
UOrb & operator=(const UOrb &rhs)
bool Normal(const UVector3 &aPoint, UVector3 &aNormal) const
Return unit normal of surface closest to p.
static double frTolerance
const std::string & GetName() const
static double fgTolerance
std::ostream & StreamInfo(std::ostream &os) const
UGeometryType GetEntityType() const
double DistanceToOutForOutsidePoints(const UVector3 &p, const UVector3 &v, UVector3 &n) const
UVector3 GetPointOnSurface() const
static double normal(HepRandomEngine *eptr)
static const double kInfinity
double SafetyFromInside(const UVector3 &aPoint, bool aAccurate=false) const
double DistanceToIn(const UVector3 &aPoint, const UVector3 &aDirection, double aPstep=UUtils::kInfinity) const
void GetParametersList(int, double *) const
double Dot(const UVector3 &) const
void Extent(UVector3 &aMin, UVector3 &aMax) const
Returns extent of the solid along a given cartesian axis OK.
void Set(double xx, double yy, double zz)
T max(const T t1, const T t2)
brief Return the largest of the two arguments
std::string UGeometryType
double SafetyFromOutside(const UVector3 &aPoint, bool aAccurate=false) const
void Exception(const char *originOfException, const char *exceptionCode, ExceptionSeverity severity, int level, const char *description)
EnumInside Inside(const UVector3 &aPo6int) const
Return whether point inside/outside/on surface Split into radius checks.
double Random(double min=0.0, double max=1.0)
double DistanceToOut(const UVector3 &aPoint, const UVector3 &aDirection, UVector3 &aNormalVector, bool &aConvex, double aPstep=UUtils::kInfinity) const