vgl_homg_line_3d_2_points.hxx
Go to the documentation of this file.
1 // This is core/vgl/vgl_homg_line_3d_2_points.hxx
2 #ifndef vgl_homg_line_3d_2_points_hxx_
3 #define vgl_homg_line_3d_2_points_hxx_
4 //:
5 // \file
6 
7 #include <iostream>
9 #include "vgl_tolerance.h"
10 #ifdef _MSC_VER
11 # include <vcl_msvc_warnings.h>
12 #endif
13 #include <cassert>
14 
15 //***************************************************************************
16 // Initialization
17 //***************************************************************************
18 
19 
20 //***************************************************************************
21 // Utility methods
22 //***************************************************************************
23 
24 template <class Type>
26 {
27  if (this==&other)
28  return true;
29  if (!point_finite().ideal()) {
30  if (point_infinite() != other.point_infinite())
31  return false;
32  if (point_finite() == other.point_finite())
33  return true;
34  // Now it suffices to check that the points are collinear:
35  return collinear(point_infinite(), point_finite(), other.point_finite());
36  }
37  // and in the case of the line being at infinity:
38  return collinear(point_infinite(), point_finite(), other.point_finite())
39  && collinear(other.point_infinite(), point_finite(), other.point_finite());
40 }
41 
42 //: force the point point_infinite_ to infinity, without changing the line
43 template <class Type>
45 {
46  //Require tolerance on ideal point
48  if (point_infinite_.w() < tol && point_infinite_.w()>-tol) return; // already OK
49  else if (point_finite_.w() < tol && point_finite_.w()>-tol) // interchange the points
50  {
51  vgl_homg_point_3d<Type> t=point_infinite_;
52  point_infinite_=point_finite_;
53  point_finite_=t;
54  return;
55  }
56  Type a=point_finite_.x(), a1=point_infinite_.x(),
57  b=point_finite_.y(), b1=point_infinite_.y(),
58  c=point_finite_.z(), c1=point_infinite_.z(),
59  d=point_finite_.w(), d1=point_infinite_.w();
60  point_infinite_.set(a*d1-a1*d, b*d1-b1*d, c*d1-c1*d, 0);
61 }
62 
63 //: Return the intersection point of two concurrent lines
64 template <class Type>
66 {
67  assert(concurrent(l1,l2));
68  Type a0=l1.point_finite().x(), a1=l1.point_infinite().x(), a2=l2.point_finite().x(), a3=l2.point_infinite().x(),
69  b0=l1.point_finite().y(), b1=l1.point_infinite().y(), b2=l2.point_finite().y(), b3=l2.point_infinite().y(),
70  c0=l1.point_finite().z(), c1=l1.point_infinite().z(), c2=l2.point_finite().z(), c3=l2.point_infinite().z(),
71  d0=l1.point_finite().w(), d1=l1.point_infinite().w(), d2=l2.point_finite().w(), d3=l2.point_infinite().w();
72  Type t1 = b3*a1-a3*b1, t2 = (a2-a0)*b3-(b2-b0)*a3;
73  if (t1==0 && t2==0)
74  t1 = c3*a1-a3*c1, t2 = (a2-a0)*c3-(c2-c0)*a3;
75  if (t1==0 && t2==0)
76  t1 = d3*a1-a3*d1, t2 = (a2-a0)*d3-(d2-d0)*a3;
77  if (t1==0 && t2==0)
78  t1 = c3*b1-b3*c1, t2 = (b2-b0)*c3-(c2-c0)*b3;
79  if (t1==0 && t2==0)
80  t1 = d3*b1-b3*d1, t2 = (b2-b0)*d3-(d2-d0)*b3;
81  if (t1==0 && t2==0)
82  t1 = d3*c1-c3*d1, t2 = (c2-c0)*d3-(d2-d0)*c3;
83  return vgl_homg_point_3d<Type>(t1*a0+t2*a1,t1*b0+t2*b1,t1*c0+t2*c1,t1*d0+t2*d1);
84 }
85 
86 //*****************************************************************************
87 // stream operators
88 //*****************************************************************************
89 
90 template <class Type>
91 std::ostream& operator<<(std::ostream &s,
93 {
94  return s << "<vgl_homg_line_3d_2_points "
95  << p.point_finite() << p.point_infinite() << " >";
96 }
97 
98 #undef VGL_HOMG_LINE_3D_2_POINTS_INSTANTIATE
99 #define VGL_HOMG_LINE_3D_2_POINTS_INSTANTIATE(T) \
100 template class vgl_homg_line_3d_2_points<T >;\
101 template std::ostream& operator<<(std::ostream&, vgl_homg_line_3d_2_points<T > const&);\
102 template vgl_homg_point_3d<T > intersection(vgl_homg_line_3d_2_points<T > const&, vgl_homg_line_3d_2_points<T > const&)
103 
104 #endif // vgl_homg_line_3d_2_points_hxx_
bool concurrent(l const &l1, l const &l2, l const &l3)
Are three lines concurrent, i.e., do they pass through a common point?.
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
Represents a homogeneous 3D point.
Definition: vgl_fwd.h:9
void force_point2_infinite(void) const
force the point point_infinite_ to infinity, without changing the line.
bool collinear(l const &l1, vgl_homg_point_3d< Type > const &p)
Does a line pass through a point, i.e., are the point and the line collinear?.
bool operator==(vgl_homg_line_3d_2_points< Type > const &l) const
comparison.
vgl_homg_point_3d< Type > intersection(l const &l1, l const &l2)
Return the intersection point of two concurrent lines.
vgl_homg_point_3d< Type > point_finite() const
Finite point (Could be an ideal point, if the whole line is at infinity.).
vgl_homg_point_3d< Type > point_infinite() const
Infinite point: the intersection of the line with the plane at infinity.
Represents a homogeneous 3D line using two points.
Definition: vgl_fwd.h:15