00001
00002 #ifndef vgl_homg_line_3d_2_points_txx_
00003 #define vgl_homg_line_3d_2_points_txx_
00004
00005
00006
00007 #include "vgl_homg_line_3d_2_points.h"
00008 #include "vgl_tolerance.h"
00009 #include <vcl_iostream.h>
00010 #include <vcl_cassert.h>
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 template <class Type>
00022 bool vgl_homg_line_3d_2_points<Type>::operator==(vgl_homg_line_3d_2_points<Type> const& other) const
00023 {
00024 if (this==&other)
00025 return true;
00026 if (!point_finite().ideal()) {
00027 if (point_infinite() != other.point_infinite())
00028 return false;
00029 if (point_finite() == other.point_finite())
00030 return true;
00031
00032 return collinear(point_infinite(), point_finite(), other.point_finite());
00033 }
00034
00035 return collinear(point_infinite(), point_finite(), other.point_finite())
00036 && collinear(other.point_infinite(), point_finite(), other.point_finite());
00037 }
00038
00039
00040 template <class Type>
00041 void vgl_homg_line_3d_2_points<Type>::force_point2_infinite(void) const
00042 {
00043
00044 Type tol = vgl_tolerance<Type>::position;
00045 if (point_infinite_.w() < tol && point_infinite_.w()>-tol) return;
00046 else if (point_finite_.w() < tol && point_finite_.w()>-tol)
00047 {
00048 vgl_homg_point_3d<Type> t=point_infinite_;
00049 point_infinite_=point_finite_;
00050 point_finite_=t;
00051 return;
00052 }
00053 Type a=point_finite_.x(), a1=point_infinite_.x(),
00054 b=point_finite_.y(), b1=point_infinite_.y(),
00055 c=point_finite_.z(), c1=point_infinite_.z(),
00056 d=point_finite_.w(), d1=point_infinite_.w();
00057 point_infinite_.set(a*d1-a1*d, b*d1-b1*d, c*d1-c1*d, 0);
00058 }
00059
00060
00061 template <class Type>
00062 vgl_homg_point_3d<Type> intersection(vgl_homg_line_3d_2_points<Type> const& l1, vgl_homg_line_3d_2_points<Type> const& l2)
00063 {
00064 assert(concurrent(l1,l2));
00065 Type a0=l1.point_finite().x(), a1=l1.point_infinite().x(), a2=l2.point_finite().x(), a3=l2.point_infinite().x(),
00066 b0=l1.point_finite().y(), b1=l1.point_infinite().y(), b2=l2.point_finite().y(), b3=l2.point_infinite().y(),
00067 c0=l1.point_finite().z(), c1=l1.point_infinite().z(), c2=l2.point_finite().z(), c3=l2.point_infinite().z(),
00068 d0=l1.point_finite().w(), d1=l1.point_infinite().w(), d2=l2.point_finite().w(), d3=l2.point_infinite().w();
00069 Type t1 = b3*a1-a3*b1, t2 = (a2-a0)*b3-(b2-b0)*a3;
00070 if (t1==0 && t2==0)
00071 t1 = c3*a1-a3*c1, t2 = (a2-a0)*c3-(c2-c0)*a3;
00072 if (t1==0 && t2==0)
00073 t1 = d3*a1-a3*d1, t2 = (a2-a0)*d3-(d2-d0)*a3;
00074 if (t1==0 && t2==0)
00075 t1 = c3*b1-b3*c1, t2 = (b2-b0)*c3-(c2-c0)*b3;
00076 if (t1==0 && t2==0)
00077 t1 = d3*b1-b3*d1, t2 = (b2-b0)*d3-(d2-d0)*b3;
00078 if (t1==0 && t2==0)
00079 t1 = d3*c1-c3*d1, t2 = (c2-c0)*d3-(d2-d0)*c3;
00080 return vgl_homg_point_3d<Type>(t1*a0+t2*a1,t1*b0+t2*b1,t1*c0+t2*c1,t1*d0+t2*d1);
00081 }
00082
00083
00084
00085
00086
00087 template <class Type>
00088 vcl_ostream& operator<<(vcl_ostream &s,
00089 const vgl_homg_line_3d_2_points<Type> &p)
00090 {
00091 return s << "<vgl_homg_line_3d_2_points "
00092 << p.point_finite() << p.point_infinite() << " >";
00093 }
00094
00095 #undef VGL_HOMG_LINE_3D_2_POINTS_INSTANTIATE
00096 #define VGL_HOMG_LINE_3D_2_POINTS_INSTANTIATE(T) \
00097 template class vgl_homg_line_3d_2_points<T >;\
00098 template vcl_ostream& operator<<(vcl_ostream&, vgl_homg_line_3d_2_points<T > const&);\
00099 template vgl_homg_point_3d<T > intersection(vgl_homg_line_3d_2_points<T > const&, vgl_homg_line_3d_2_points<T > const&)
00100
00101 #endif // vgl_homg_line_3d_2_points_txx_