All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbncode/sbncode/OpT0Finder/flashmatch/GeoAlgo/GeoCylinder.cxx
Go to the documentation of this file.
1 #ifndef BASICTOOL_GEOCYLINDER_CXX
2 #define BASICTOOL_GEOCYLINDER_CXX
3 
4 #include "GeoCylinder.h"
5 
6 namespace geoalgo {
7 
9  : Line()
10  , _radius (0.)
11  {}
12 
13  Cylinder::Cylinder(const double x_min, const double y_min, const double z_min,
14  const double x_max, const double y_max, const double z_max,
15  const double radius)
16  : Line(x_min, y_min, z_min, x_max, y_max, z_max)
17  , _radius ( radius )
18  {}
19 
20  Cylinder::Cylinder(const Point_t& min, const Vector_t& max, const double radius)
21  : Line(min, max)
22  , _radius ( radius )
23  {
24  if(min.size()!=3 || max.size()!=3)
25  throw GeoAlgoException("Cylinder ctor accepts only 3D Point!");
26  }
27 
28  bool Cylinder::Contain(const Point_t &pt) const {
29 
30  // get a vector that defines the axis of the cylinder
31  Vector_t axis = _pt1-_pt2;
32  Vector_t dirpt = pt-_pt2;
33 
34  // angle of point w.r.t. the axis
35  double angleMin = axis.Angle(dirpt);
36 
37  // if the angle is > 90 -> outside -> return
38  if (angleMin > 0.5*3.14)
39  return false;
40 
41  // revert the axis direction
42  axis = _pt2-_pt1;
43  dirpt = pt-_pt1;
44  angleMin = axis.Angle(dirpt);
45 
46  // if the angle is > 90 -> outside -> return
47  if (angleMin > 0.5*3.14)
48  return false;
49 
50  // if still here, all that is left to verify is
51  // that the point isn't more than a radius
52  // away from the cylinder axis
53  // 1) make a line corresponding to the axis
54  // 2) get the distance between the point and the line
55  double radial_dist_sq = _geoAlgo.SqDist(*this,pt);
56 
57  if (radial_dist_sq > _radius*_radius)
58  return false;
59 
60  return true;
61 
62  }
63 }
64 #endif
65 
66 
double SqDist(const Line_t &line, const Point_t &pt) const
Point_t _pt1
First point denoting infinite line.
recob::tracking::Point_t Point_t
double _radius
Radius of the cylinder.
bool Contain(const Point_t &pt) const
Containment evaluation.
Vector_t _pt2
Second point denoting infinite line.
recob::tracking::Vector_t Vector_t
double Angle(const Vector &obj) const
Compute a cross product of two vectors.