~esys-p-dev/esys-particle/gengeo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/////////////////////////////////////////////////////////////
//                                                         //
// Copyright (c) 2007-2014 by The University of Queensland //
// Centre for Geoscience Computing                         //
// http://earth.uq.edu.au/centre-geoscience-computing      //
//                                                         //
// Primary Business: Brisbane, Queensland, Australia       //
// Licensed under the Open Software License version 3.0    //
// http://www.opensource.org/licenses/osl-3.0.php          //
//                                                         //
/////////////////////////////////////////////////////////////

#include "DogBone.h"

// --- STL includes ---
#include <utility>

using std::make_pair;

DogBone::DogBone()
{}

/*!
  \param c base point
  \param axis central axis
  \param l total length
  \param r total radius
  \param l2 length of cylindrical end pieces
  \param r2 center radius
*/
DogBone::DogBone(const Vector3& c,const Vector3& axis,double l,double r,double l2,double r2) : CylinderVol(c,axis,l,r)
{
  // calc torus center
  Vector3 tcenter=c+0.5*l*axis;

  // torus inner radius
  double h=0.5*l-l2;
  double k=(r-r2);
  double ri=0.5*(k+(h*h)/k);
  
  // torus outer radius
  double ro=ri+r2;

  std::cerr << "torus: " << tcenter << " - " << ro << " , " << ri << std::endl;
  m_tor=Torus(tcenter,axis,ro,ri,false);
}

const map<double,const AGeometricObject*> DogBone::getClosestObjects(const Vector3& P,int n) const
{
  map<double,const AGeometricObject*> res=CylinderVol::getClosestObjects(P,n);

  res.insert(make_pair(m_tor.getDist(P),&m_tor));
  
  return res;
}

bool DogBone::isIn(const Vector3& P) const
{
  bool res=CylinderVol::isIn(P);

  bool in_torus=(m_tor.getDist(P)>0);

  return res && in_torus;
}

bool DogBone::isIn(const Sphere& S)
{
  bool res=CylinderVol::isIn(S);

  bool in_torus=(m_tor.getDist(S.Center())>S.Radius());

  return res && in_torus;
}