00001 #include <CGAL/Object.h>
00002 #include <CGAL/Point_3.h>
00003 #include <CGAL/Vector_3.h>
00004 #include <CGAL/predicates_on_points_3.h>
00005
00006
00007 namespace CEP {
00008 namespace intersection {
00009
00010 namespace Line_3_Line_3 {
00011
00018 template <class R>
00019 CGAL::Object
00020 coplanar_nonparallel_intersection( const Point_3<R>& p,
00021 const Point_3<R>& q,
00022 const Point_3<R>& r,
00023 const Point_3<R>& s )
00024 {
00025 CGAL_exactness_precondition( CGAL::coplanar(p,q,r,s) );
00026
00027 typedef typename R::FT FT;
00028
00029 CGAL::Vector_3<R> d1 = q - p;
00030 CGAL::Vector_3<R> d2 = s - r;
00031 CGAL::Vector_3<R> b = r - p;
00032
00033
00034
00035 FT num = (d2*d2) * (d1*b) - (d1*d2) * (d2*b);
00036 FT den = (d1*d1) * (d2*d2) - (d1*d2) * (d1*d2);
00037
00038 FT zero(0);
00039 CGAL_exactness_assertion( den != zero );
00040
00041 Point_3<R> i_point = p + d1 * num / den;
00042 return CGAL::make_object(i_point);
00043 }
00044
00045
00051 template <class R>
00052 CGAL::Object
00053 coplanar_intersection( const Point_3<R>& p,
00054 const Point_3<R>& q,
00055 const Point_3<R>& r,
00056 const Point_3<R>& s )
00057 {
00058 CGAL_exactness_precondition( CGAL::coplanar(p,q,r,s) );
00059
00060 CGAL::Vector_3<R> d1 = q-p;
00061 CGAL::Vector_3<R> d2 = s-r;
00062
00063 if ( d1.direction() == d2.direction() ||
00064 d1.direction() == -d2.direction() )
00065 return CGAL::Object();
00066
00067 return coplanar_nonparallel_intersection(p,q,r,s);
00068 }
00069
00070
00071 }
00072 }
00073 }
00074