Point.cxx
Go to the documentation of this file.
1 #include "WireCellUtil/Point.h"
2 
3 #include <algorithm> // minmax
4 
5 namespace instantiations {
6 
13 
14 
15 }
16 
17 // std::ostream& operator<<(std::ostream& os, const WireCell::Ray& ray)
18 // {
19 // os << "[" << ray.first << " --> " << ray.second << "]";
20 // return os;
21 // }
22 
23 
25  const WireCell::Point& rhs) const
26 {
27  double mag = (lhs-rhs).magnitude();
28  if (mag < 1e-10) {
29  return false; // consider them equal
30  }
31  // otherwise, order them by x,y,z
32  for (int ind=0; ind<3; ++ind) {
33  if (lhs[ind] < rhs[ind]) {
34  return true;
35  }
36  }
37  return false;
38 }
39 
41 {
42  for (int axis = 0; axis<3; ++axis) {
43  if (!point_contained(point, bounds, axis)) {
44  return false;
45  }
46  }
47  return true;
48 }
49 
50 bool WireCell::point_contained(const WireCell::Point& point, const WireCell::Ray& bounds, int axis)
51 {
52  std::pair<double, double> mm = std::minmax(bounds.first[axis], bounds.second[axis]);
53  return mm.first <= point[axis] && point[axis] <= mm.second;
54 }
55 
56 
58 {
59  return acos(axis.dot(vector));
60 }
61 
63 {
64  return (ray.second - ray.first).magnitude();
65 }
66 
68 {
69  return ray.second - ray.first;
70 }
72 {
73  return ray_vector(ray).norm();
74 }
75 
77 {
78  // http://geomalgorithms.com/a07-_distance.html
79  const WireCell::Vector w0 = pu.first - qv.first;
80  const WireCell::Vector u = ray_unit(pu);
81  const WireCell::Vector v = ray_unit(qv);
82  const double a = u.dot(u), b = u.dot(v), c = v.dot(v);
83  const double d = u.dot(w0), e = v.dot(w0);
84 
85  const double denom = a*c - b*b;
86  if (denom < 1e-6) { // parallel
87  double t = e/c;
88  return Ray(pu.first, qv.first + t*v);
89  }
90  const double s = (b*e - c*d) / denom;
91  const double t = (a*e - b*d) / denom;
92  return Ray(pu.first + s*u, qv.first + t*v);
93 }
94 
95 double WireCell::ray_dist(const WireCell::Ray& ray, const WireCell::Point& point)
96 {
97  return ray_unit(ray).dot(point - ray.first);
98 }
99 
100 
102 {
103  auto diff = ray_vector(ray);
104  return diff.x() * diff.y() * diff.z();
105 }
106 
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition: Point.h:21
std::pair< float, float > minmax(const float a, const float b)
minmax
bool operator()(const Point &lhs, const Point &rhs) const
Definition: Point.cxx:24
WireCell::PointF a_sad_little_point
Definition: Point.cxx:12
WireCell::PointValueVector a_point_value_vector
Definition: Point.cxx:11
std::pair< Point, float > PointValue
PointValue - an association of a point and a value.
Definition: Point.h:37
std::vector< PointValue > PointValueVector
PointValueVector - a collection of point-value associations.
Definition: Point.h:40
double ray_dist(const Ray &ray, const Point &point)
Definition: Point.cxx:95
double ray_volume(const Ray &ray)
Definition: Point.cxx:101
const double e
double ray_length(const Ray &ray)
Definition: Point.cxx:62
D3Vector norm() const
Return a normalized vector in the direction of this vector.
Definition: D3Vector.h:91
WireCell::Point a_point
Definition: Point.cxx:7
Vector ray_unit(const Ray &ray)
Definition: Point.cxx:71
WireCell::PointValue a_point_value
Definition: Point.cxx:10
BoundingBox bounds(int x, int y, int w, int h)
Definition: main.cpp:37
static const double mm
Definition: Units.h:73
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
std::vector< Point > PointVector
PointVector - a collection of Points.
Definition: Point.h:30
Ray ray_pitch(const Ray &ray1, const Ray &ray2)
Definition: Point.cxx:76
T dot(const D3Vector &rhs) const
Return the dot product of this vector and the other.
Definition: D3Vector.h:80
realseq_t magnitude(const compseq_t &seq)
Return the magnitude or absolute value of the sequence.
Definition: Waveform.cxx:65
WireCell::PointVector a_point_vector
Definition: Point.cxx:9
static bool * b
Definition: config.cpp:1043
WireCell::Ray a_ray
Definition: Point.cxx:8
double point_angle(const Vector &axis, const Vector &vector)
Definition: Point.cxx:57
bool point_contained(const Point &point, const Ray &bounds)
Definition: Point.cxx:40
Vector ray_vector(const Ray &ray)
Definition: Point.cxx:67
static QCString * s
Definition: config.cpp:1042