vgl_infinite_line_3d.h
Go to the documentation of this file.
1 // This is core/vgl/vgl_infinite_line_3d.h
2 #ifndef vgl_infinite_line_3d_h_
3 #define vgl_infinite_line_3d_h_
4 //:
5 // \file
6 // \brief A 3-d infinite line with position parameterized by orthogonal plane coordinates
7 // \author J.L. Mundy
8 //
9 // \verbatim
10 // Modifications
11 // Initial version July 25, 2009
12 // \endverbatim
13 
14 #include <iosfwd>
15 #ifdef _MSC_VER
16 # include <vcl_msvc_warnings.h>
17 #endif
18 #include <vgl/vgl_vector_2d.h>
19 #include <vgl/vgl_vector_3d.h>
20 #include <vgl/vgl_point_3d.h>
23 
24 //: Represents a 3-d line with position defined in the orthogonal plane passing through the origin.
25 // The line direction is t_.
26 // The 2-d plane coordinate system (u, v) is aligned with the 3-d coordinate
27 // system (X, Y, X), where v = t x X and u = v x t.
28 template <class Type>
30 {
31  vgl_vector_2d<Type> x0_; //!< line position vector
32  vgl_vector_3d<Type> t_; //!< line direction vector (tangent)
33  public:
34  //: Default constructor - does not initialise!
35  inline vgl_infinite_line_3d() = default;
36 
37  //: Copy constructor
39  : x0_(l.x0()), t_(l.direction()) {}
40 
41  //: Construct from x0 and direction
44  : x0_(x_0), t_(direction) {}
45 
46  //: Construct from two points
48  vgl_point_3d<Type> const& p2);
49 
50  //: Construct from a point and direction
53 
54  //: Construct from a line segment
56  {
57  vgl_infinite_line_3d<Type> inf_l(ls.point1(), ls.point2());
58  x0_ = inf_l.x0(); t_ = inf_l.direction();
59  }
60 
61  //: Construct from a line 2 points
63  {
64  vgl_infinite_line_3d<Type> inf_l(ls.point1(), ls.point2());
65  x0_ = inf_l.x0(); t_ = inf_l.direction();
66  }
67 
68  //: Destructor
69  inline ~vgl_infinite_line_3d() = default;
70 
71  //: Accessors
72  inline vgl_vector_2d<Type> x0() const { return x0_; } // return a copy
74  { return t_/static_cast<Type>(t_.length()); } // return a copy
75 
76  //: The comparison operator
77  inline bool operator==(vgl_infinite_line_3d<Type> const& l) const
78  { return (this==&l) || (direction() == l.direction() && x0() == l.x0()); }
79 
80  inline bool operator!=(vgl_infinite_line_3d<Type>const& other) const
81  { return !operator==(other); }
82 
83  //: Assignment
84  inline void set(vgl_vector_2d<Type> const& x_0, vgl_vector_3d<Type> const& direction)
85  { x0_ = x_0; t_ = direction; }
86 
87  //: Return the point on the line closest to the origin
88  vgl_point_3d<Type> point() const;
89 
90  //: Return a point on the line defined by a scalar parameter \a t.
91  // \a t=0.0 corresponds to the closest point on the line to the origin
92  vgl_point_3d<Type> point_t(const double t) const { return point() + t*direction(); }
93 
94  //: Check if point \a p is on the line
95  bool contains(const vgl_point_3d<Type>& p ) const;
96 
97  //: The unit vectors perpendicular to the line direction
99 };
100 
101 //: Write to stream
102 // \relatesalso vgl_infinite_line_3d
103 template <class Type>
104 std::ostream& operator<<(std::ostream& s, const vgl_infinite_line_3d<Type>& p);
105 
106 //: Read from stream
107 // \relatesalso vgl_infinite_line_3d
108 template <class Type>
109 std::istream& operator>>(std::istream& is, vgl_infinite_line_3d<Type>& p);
110 #define VGL_INFINITE_LINE_3D_INSTANTIATE(T) extern "please include vgl/vgl_infinite_line_3d.hxx first"
111 
112 #endif // vgl_infinite_line_3d_h_
~vgl_infinite_line_3d()=default
Destructor.
vgl_infinite_line_3d(vgl_vector_2d< Type > const &x_0, vgl_vector_3d< Type > const &direction)
Construct from x0 and direction.
vgl_point_3d< Type > point1() const
vgl_vector_2d< Type > x0() const
Accessors.
bool operator==(vgl_infinite_line_3d< Type > const &l) const
The comparison operator.
vgl_vector_3d< Type > direction() const
vgl_point_3d< Type > point2() const
direction vector in Euclidean 3D space
Represents a cartesian 3D point.
Definition: vgl_fwd.h:11
bool contains(const vgl_point_3d< Type > &p) const
Check if point p is on the line.
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
vgl_infinite_line_3d(vgl_line_3d_2_points< Type > const &ls)
Construct from a line 2 points.
vgl_infinite_line_3d(vgl_line_segment_3d< Type > const &ls)
Construct from a line segment.
vgl_vector_2d< Type > x0_
line position vector
A class to hold a non-homogeneous representation of a 3D line.
Definition: vgl_fwd.h:17
#define v
Definition: vgl_vector_2d.h:74
vgl_vector_3d< Type > t_
line direction vector (tangent)
bool operator!=(vgl_infinite_line_3d< Type >const &other) const
a point in 3D nonhomogeneous space
line segment in 3D nonhomogeneous space
double length() const
Return the length of this vector.
vgl_point_3d< Type > point_t(const double t) const
Return a point on the line defined by a scalar parameter t.
vgl_point_3d< Type > point1() const
Return the first point representing this line.
vgl_infinite_line_3d(vgl_infinite_line_3d< Type > const &l)
Copy constructor.
Represents a 3D line segment using two points.
Definition: vgl_fwd.h:19
void set(vgl_vector_2d< Type > const &x_0, vgl_vector_3d< Type > const &direction)
Assignment.
direction vector in Euclidean 2D space
Represents a 3-d line with position defined in the orthogonal plane passing through the origin.
Definition: vgl_fwd.h:20
vgl_infinite_line_3d()=default
Default constructor - does not initialise!.
std::istream & operator>>(std::istream &is, vgl_orient_box_3d< Type > &p)
Read box from stream.
#define l
vgl_point_3d< Type > point2() const
Return the second point representing this line.
non-homogeneous 3D line, represented by 2 points.
void compute_uv_vectors(vgl_vector_3d< Type > &u, vgl_vector_3d< Type > &v) const
The unit vectors perpendicular to the line direction.
vgl_point_3d< Type > point() const
Return the point on the line closest to the origin.