replaced segmentsegmentintersection implementation
This commit is contained in:
parent
d2b0ac56c7
commit
8ac85892e3
|
@ -187,39 +187,38 @@ namespace vcg {
|
|||
return ((d0<length)&&(d1<length));
|
||||
}
|
||||
|
||||
/// interseciton between point and triangle
|
||||
/// interseciton between two segments
|
||||
template<class SCALAR_TYPE>
|
||||
inline bool SegmentSegmentIntersection(const vcg::Segment2<SCALAR_TYPE> &seg0,
|
||||
const vcg::Segment2<SCALAR_TYPE> &seg1,
|
||||
Point2<SCALAR_TYPE> &p_inters)
|
||||
{
|
||||
vcg::Line2<SCALAR_TYPE> l0,l1;
|
||||
const SCALAR_TYPE Eps= SCALAR_TYPE(1e-8);
|
||||
SCALAR_TYPE lambda0,lambda1;
|
||||
const Point2<SCALAR_TYPE> & p0 = seg0.P0();
|
||||
const Point2<SCALAR_TYPE> & p1 = seg0.P1();
|
||||
const Point2<SCALAR_TYPE> & p2 = seg1.P0();
|
||||
const Point2<SCALAR_TYPE> & p3 = seg1.P1();
|
||||
|
||||
l0.SetOrigin(seg0.P0());
|
||||
vcg::Point2<SCALAR_TYPE> dir0=seg0.P1()-seg0.P0();
|
||||
dir0.Normalize();
|
||||
l0.SetDirection(dir0);
|
||||
SCALAR_TYPE a = (p1-p0)[0];
|
||||
SCALAR_TYPE b = (p2-p3)[0];
|
||||
SCALAR_TYPE c = (p1-p0)[1];
|
||||
SCALAR_TYPE d = (p2-p3)[1];
|
||||
|
||||
l1.SetOrigin(seg1.P0());
|
||||
vcg::Point2<SCALAR_TYPE> dir1=seg1.P1()-seg1.P0();
|
||||
dir1.Normalize();
|
||||
l1.SetDirection(dir1);
|
||||
LineLineIntersection(l0,l1,p_inters);
|
||||
SCALAR_TYPE len0=seg0.Length();
|
||||
SCALAR_TYPE len1=seg1.Length();
|
||||
SCALAR_TYPE d0=(seg0.P0()-p_inters).Norm();
|
||||
SCALAR_TYPE d1=(seg1.P0()-p_inters).Norm();
|
||||
SCALAR_TYPE e = (p2-p0)[0];
|
||||
SCALAR_TYPE f = (p2-p0)[1];
|
||||
|
||||
if ((d0>len0)||(d1>len1))
|
||||
SCALAR_TYPE det = a*d-b*c;
|
||||
|
||||
lambda0 = (d*e-b*f)/det;
|
||||
lambda1 = (-c*e+a*f)/det;
|
||||
if (fabs(det)<Eps)
|
||||
return false;// they are parallell
|
||||
|
||||
if (!(lambda0 >= 0.0 && lambda0 <= 1.0 && lambda1 >= 0.0 && lambda1 <= 1.0))
|
||||
return false;
|
||||
|
||||
vcg::Point2<SCALAR_TYPE> dir2=p_inters-seg0.P0();
|
||||
vcg::Point2<SCALAR_TYPE> dir3=p_inters-seg1.P0();
|
||||
if (((dir2*dir0)<0)||((dir3*dir1)<0))
|
||||
return false;
|
||||
|
||||
p_inters = p0*(1-lambda0)+p1*lambda0;
|
||||
return true;
|
||||
|
||||
}
|
||||
/// interseciton between point and triangle
|
||||
template<class SCALAR_TYPE>
|
||||
|
|
Loading…
Reference in New Issue