| 1 |
///////////////////////////////////////////////////////////// |
| 2 |
// // |
| 3 |
// Copyright (c) 2007-2017 by The University of Queensland // |
| 4 |
// Centre for Geoscience Computing // |
| 5 |
// http://earth.uq.edu.au/centre-geoscience-computing // |
| 6 |
// // |
| 7 |
// Primary Business: Brisbane, Queensland, Australia // |
| 8 |
// Licensed under the Open Software License version 3.0 // |
| 9 |
// http://www.apache.org/licenses/LICENSE-2.0 // |
| 10 |
// // |
| 11 |
///////////////////////////////////////////////////////////// |
| 12 |
|
| 13 |
#include "SphereVol.h" |
| 14 |
|
| 15 |
//--- |
| 16 |
#include <cmath> |
| 17 |
#include <cstdlib> |
| 18 |
|
| 19 |
using std::cos; |
| 20 |
using std::sin; |
| 21 |
|
| 22 |
// --- STL includes --- |
| 23 |
#include <utility> |
| 24 |
|
| 25 |
using std::make_pair; |
| 26 |
|
| 27 |
SphereVol::SphereVol() |
| 28 |
{} |
| 29 |
|
| 30 |
SphereVol::SphereVol(const Vector3& c,double r) |
| 31 |
{ |
| 32 |
m_sph=SphereIn(c,r); |
| 33 |
} |
| 34 |
|
| 35 |
pair<Vector3,Vector3> SphereVol::getBoundingBox() |
| 36 |
{ |
| 37 |
Vector3 r=Vector3(m_sph.Radius(),m_sph.Radius(),m_sph.Radius()); |
| 38 |
return make_pair(m_sph.Center()-r,m_sph.Center()+r); |
| 39 |
} |
| 40 |
|
| 41 |
Vector3 SphereVol::getAPoint(int) const |
| 42 |
{ |
| 43 |
double r=m_sph.Radius()*((double)(rand())/(double)(RAND_MAX)); |
| 44 |
double phi=M_PI*((double)(rand())/(double)(RAND_MAX)); |
| 45 |
double rho=2*M_PI*((double)(rand())/(double)(RAND_MAX)); |
| 46 |
|
| 47 |
return m_sph.Center()+r*Vector3(sin(phi)*cos(rho),sin(phi)*sin(rho),cos(phi)); |
| 48 |
} |
| 49 |
|
| 50 |
const map<double,const AGeometricObject*> SphereVol::getClosestObjects(const Vector3& P,int) const |
| 51 |
{ |
| 52 |
map<double,const AGeometricObject*> res; |
| 53 |
|
| 54 |
res.insert(make_pair(m_sph.getDist(P),&m_sph)); |
| 55 |
|
| 56 |
return res; |
| 57 |
} |
| 58 |
|
| 59 |
bool SphereVol::isIn(const Vector3& P) const |
| 60 |
{ |
| 61 |
return (m_sph.getDirDist(P)>0); |
| 62 |
} |
| 63 |
|
| 64 |
bool SphereVol::isIn(const Sphere& S) |
| 65 |
{ |
| 66 |
return (m_sph.getDirDist(S.Center())>S.Radius()); |
| 67 |
} |
| 68 |
|
| 69 |
/* |
| 70 |
check if sphere is fully outside volume. |
| 71 |
|
| 72 |
\param S the sphere |
| 73 |
*/ |
| 74 |
bool SphereVol::isFullyOutside(const Sphere& S) |
| 75 |
{ |
| 76 |
double d=(m_sph.Center()-S.Center()).norm(); |
| 77 |
return d>(m_sph.Radius()+S.Radius()); |
| 78 |
} |
| 79 |
|
| 80 |
ostream& operator << (ostream& ost,const SphereVol& T) |
| 81 |
{ |
| 82 |
return ost; |
| 83 |
} |