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