Minor changes in ClosestPoint function
This commit is contained in:
parent
61d01309ac
commit
e90c417d2b
|
@ -148,26 +148,16 @@ Point2<ScalarType> ClosestPoint( Segment2<ScalarType> s, const Point2<ScalarType
|
||||||
{
|
{
|
||||||
vcg::Line2<ScalarType> l;
|
vcg::Line2<ScalarType> l;
|
||||||
l.Set(s.P0(),s.P1()-s.P0());
|
l.Set(s.P0(),s.P1()-s.P0());
|
||||||
l.Normalize();
|
l = l.Normalize();
|
||||||
Point2<ScalarType> clos=vcg::ClosestPoint<ScalarType,true>(l,p) ;//attention to call
|
ScalarType t = l.Projection(p);
|
||||||
vcg::Box2<ScalarType> b;
|
Point2<ScalarType> clos = l.P(t);
|
||||||
b.Add(s.P0());
|
int lenght = s.Length();
|
||||||
b.Add(s.P1());
|
if (t <= 0)
|
||||||
if (b.IsIn(clos))
|
return s.P0();
|
||||||
return clos;
|
else if (t >= lenght)
|
||||||
|
return s.P1();
|
||||||
else
|
else
|
||||||
{
|
return clos;
|
||||||
ScalarType d0=(s.P0()-p).Norm();
|
|
||||||
ScalarType d1=(s.P1()-p).Norm();
|
|
||||||
if (d0<d1)
|
|
||||||
return (s.P0());
|
|
||||||
else
|
|
||||||
return (s.P1());
|
|
||||||
}
|
|
||||||
/*ScalarType t = s.Projection(p);
|
|
||||||
if (s<0) return s.P0();
|
|
||||||
if (s>1) return s.P0();
|
|
||||||
return s.P(t);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
Loading…
Reference in New Issue