Segment.h
Go to the documentation of this file.
1 #ifndef _utl_Segment_h_
2 #define _utl_Segment_h_
3 
4 #include <utl/Point.h>
5 #include <utl/Vector.h>
6 
7 
8 namespace utl {
9 
18  class Segment {
19  public:
25  Segment(const Point& b, const Point& e) :
26  fBegin(b),
27  fEnd(e),
28  fDirection(e - b)
29  {
31  // Normalize.
32  fDirection *= 1/fLength;
33  }
34 
36  const Point& GetBegin() const { return fBegin; }
37 
39  const Point& GetEnd() const { return fEnd; }
40 
42  const Vector& GetDirection() const { return fDirection; }
43 
45  double GetLength() const { return fLength; }
46 
47  private:
53  double fLength;
54  /*
55  * RFG 20090930
56  * In the geometry package there's AxialVector, Vector and Point; and some derived objects
57  * like Line and Plane. Since a Vector is not modified upon transalation, is not the right
58  * choice to represent a segment between two points (like the track of a particle inside a
59  * detector).
60  * As seen, this class is pretty silly as itself, but seems the right choice instead of using
61  * an std:pair (which one is the start, first or second?) or the two points separately.
62  * Taking a look at preexisting classes it's seen:
63  * - FdProfileReconstructor uses a std::vector<utl::Point>.
64  * - TelescopeSimulatorKG::RayTrace::DrawTrack (const utl::Point &p1, const utl::Point &p2, int color) const.
65  * - In atm::VMieModel, for instance, there are several methods that take two points.
66  *
67  * Up to now, as said, this class is a little silly, later on it can be extended with more operations or,
68  * more likely, with proper non-member operators.
69  */
70  };
71 
72 }
73 
74 
75 #endif
const Point & GetEnd() const
Return the final point.
Definition: Segment.h:39
Point fEnd
Definition: Segment.h:49
Point object.
Definition: Point.h:32
Point fBegin
Definition: Segment.h:48
double GetMag() const
Definition: Vector.h:58
double GetLength() const
Return the length of the segment (ie the distance between begin and end).
Definition: Segment.h:45
double fLength
and so the length.
Definition: Segment.h:53
const Point & GetBegin() const
Return the initial point.
Definition: Segment.h:36
Vector fDirection
Compute the vector once.
Definition: Segment.h:51
Vector object.
Definition: Vector.h:30
Segment(const Point &b, const Point &e)
Construct the segment between the given two points.
Definition: Segment.h:25
const Vector & GetDirection() const
Return the (normalized) direction vector.
Definition: Segment.h:42
A segment joins two points.
Definition: Segment.h:18

, generated on Tue Sep 26 2023.