~ubuntu-branches/ubuntu/quantal/python-demgengeo/quantal

« back to all changes in this revision

Viewing changes to src/SphereSectionVol.cc

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2011-11-18 21:47:18 UTC
  • Revision ID: package-import@ubuntu.com-20111118214718-4ysqm3dhpqwdd7gd
Tags: upstream-0.99~bzr106
ImportĀ upstreamĀ versionĀ 0.99~bzr106

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/////////////////////////////////////////////////////////////
 
2
//                                                         //
 
3
// Copyright (c) 2007-2011 by The University of Queensland //
 
4
// Earth Systems Science Computational Centre (ESSCC)      //
 
5
// http://www.uq.edu.au/esscc                              //
 
6
//                                                         //
 
7
// Primary Business: Brisbane, Queensland, Australia       //
 
8
// Licensed under the Open Software License version 3.0    //
 
9
// http://www.opensource.org/licenses/osl-3.0.php          //
 
10
//                                                         //
 
11
/////////////////////////////////////////////////////////////
 
12
 
 
13
#include "SphereSectionVol.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
SphereSectionVol::SphereSectionVol()
 
28
{}
 
29
 
 
30
SphereSectionVol::SphereSectionVol(const Vector3& c,const double r,const double h, const Vector3& n)
 
31
{
 
32
  m_sph=SphereIn(c,r);
 
33
  m_section_dist = h;
 
34
  m_section_normal = n;
 
35
}
 
36
 
 
37
pair<Vector3,Vector3> SphereSectionVol::getBoundingBox()
 
38
{
 
39
  Vector3 r=Vector3(m_sph.Radius(),m_sph.Radius(),m_sph.Radius());
 
40
  return make_pair(m_sph.Center()-r,m_sph.Center()+r);
 
41
}
 
42
 
 
43
Vector3 SphereSectionVol::getAPoint(int) const
 
44
{
 
45
  double r=m_sph.Radius()*((double)(rand())/(double)(RAND_MAX));
 
46
  double phi=M_PI*((double)(rand())/(double)(RAND_MAX));
 
47
  double rho=2*M_PI*((double)(rand())/(double)(RAND_MAX));
 
48
 
 
49
  return m_sph.Center()+r*Vector3(sin(phi)*cos(rho),sin(phi)*sin(rho),cos(phi));
 
50
}
 
51
 
 
52
const map<double,const AGeometricObject*> SphereSectionVol::getClosestObjects(const Vector3& P,int) const
 
53
{
 
54
  map<double,const AGeometricObject*> res;
 
55
 
 
56
  res.insert(make_pair(m_sph.getDist(P),&m_sph));
 
57
 
 
58
  return res;  
 
59
}
 
60
 
 
61
bool SphereSectionVol::isIn(const Vector3& P) const
 
62
{
 
63
  double dist;
 
64
  bool isInSection;
 
65
  Vector3 posn_vector;
 
66
  double norm_comp;
 
67
 
 
68
  isInSection = false;
 
69
  posn_vector = P - m_sph.Center();
 
70
  dist = posn_vector.norm();
 
71
  if (dist<m_sph.Radius()) {
 
72
     norm_comp = dot(posn_vector,m_section_normal);
 
73
     if ((norm_comp < 0)&&(fabs(norm_comp)>m_section_dist)) {
 
74
        if ((fabs(norm_comp)/dist - m_section_dist/m_sph.Radius()) > 0) {
 
75
           isInSection = true;
 
76
        }
 
77
     }
 
78
  }
 
79
 
 
80
  return (isInSection);
 
81
}
 
82
 
 
83
bool SphereSectionVol::isIn(const Sphere& S)
 
84
{
 
85
   bool isInSection;
 
86
 
 
87
   isInSection = false;
 
88
 
 
89
   if ((isIn(S.Center()))&&(m_sph.getDist(S.Center())>S.Radius())) {
 
90
      isInSection = true;
 
91
   }
 
92
  return (isInSection);
 
93
}
 
94
 
 
95
/*
 
96
  Check if sphere is fully outside the volume.
 
97
 
 
98
  \param S the sphere
 
99
  \warning DUMMY IMPLEMENTATION
 
100
*/
 
101
bool SphereSectionVol::isFullyOutside(const Sphere& S)
 
102
{
 
103
  return true;
 
104
}
 
105
 
 
106
ostream& operator << (ostream& ost,const SphereSectionVol& T)
 
107
{
 
108
   return ost;
 
109
}