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