2 #ifndef vgl_lineseg_test_hxx_ 3 #define vgl_lineseg_test_hxx_ 13 # include <vcl_msvc_warnings.h> 23 return (a<=0 && b>=0) || (a>=0 && b<=0);
30 bool inbetween(T x1, T y1, T x2, T y2, T x3, T y3)
32 return (x1-x3)*(x2-x3)<=0 && (y1-y3)*(y2-y3)<=0;
50 px1 = (px1 + px1*1e4) - px1*1e4;
51 py1 = (py1 + py1*1e4) - py1*1e4;
52 px2 = (px2 + px2*1e4) - px2*1e4;
53 py2 = (py2 + py2*1e4) - py2*1e4;
54 px3 = (px3 + px3*1e4) - px3*1e4;
55 py3 = (py3 + py3*1e4) - py3*1e4;
56 px4 = (px4 + px4*1e4) - px4*1e4;
57 py4 = (py4 + py4*1e4) - py4*1e4;
69 a = (std::abs(a) < 1e-12) ? 0 : a;
70 b = (std::abs(b) < 1e-12) ? 0 : b;
71 c = (std::abs(c) < 1e-12) ? 0 : c;
72 d = (std::abs(d) < 1e-12) ? 0 : d;
75 ( ( (a<=0 && b>0) || (a>=0 && b<0) || (a<0 && b>=0) || (a>0 && b<=0) ) &&
76 ( (c<=0 && d>0) || (c>=0 && d<0) || (c<0 && d>=0) || (c>0 && d<=0) ) )
79 a == 0 && b == 0 && c == 0 && d == 0 &&
80 ( inbetween(px1, py1, px2, py2, px3, py3) ||
81 inbetween(px1, py1, px2, py2, px4, py4) ||
82 inbetween(px3, py3, px4, py4, px1, py1) ||
83 inbetween(px3, py3, px4, py4, px2, py2) )
95 T x1 = p1.
x(), y1 = p1.
y(),
96 x2 = p2.x(), y2 = p2.y(),
97 xp = p.
x(), yp = p.
y();
99 double d1p = static_cast<double>((xp-x1)*(xp-x1) + (yp-y1)*(yp-y1));
100 double d2p = static_cast<double>((xp-x2)*(xp-x2) + (yp-y2)*(yp-y2));
101 double d12 = static_cast<double>((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
102 double diff = std::sqrt(d1p) + std::sqrt(d2p) - std::sqrt(d12);
104 return diff <= vgl_tolerance<double>::position;
109 #undef VGL_LINESEG_TEST_INSTANTIATE 110 #define VGL_LINESEG_TEST_INSTANTIATE(T) \ 111 template bool vgl_lineseg_test_line(T, T, T, T, T, T, T, T); \ 112 template bool vgl_lineseg_test_lineseg(T, T, T, T, T, T, T, T) 114 #endif // vgl_lineseg_test_hxx_ bool vgl_lineseg_test_line(vgl_line_2d< T > const &l1, vgl_line_segment_2d< T > const &l2)
true if the line meets the linesegment.
vgl_point_2d< Type > point2() const
The other end-point of the line segment.
bool vgl_lineseg_test_lineseg(vgl_line_segment_2d< T > const &l1, vgl_line_segment_2d< T > const &l2)
return true if the two linesegments meet.
T vgl_triangle_test_discriminant(T x1, T y1, T x2, T y2, T x3, T y3)
Compute discriminant function.
vgl_point_2d< Type > point1() const
One end-point of the line segment.
bool vgl_lineseg_test_point(vgl_point_2d< T > const &p, vgl_line_segment_2d< T > const &lseg)
true if the point lies on the line segment and is between the endpoints.