- SquaredDistance moved to distance3.h
- Lenght and SquaredLength changed to const functions
This commit is contained in:
parent
6ad59d0756
commit
793cf46180
|
|
@ -117,10 +117,10 @@ public:
|
||||||
if (_p0[2]<_p1[2]) { t.min[2]=_p0[2];t.max[2]=_p1[2];} else { t.min[2]=_p1[2];t.max[2]=_p0[2];}
|
if (_p0[2]<_p1[2]) { t.min[2]=_p0[2];t.max[2]=_p1[2];} else { t.min[2]=_p1[2];t.max[2]=_p0[2];}
|
||||||
return t; }
|
return t; }
|
||||||
/// returns segment length
|
/// returns segment length
|
||||||
ScalarType Length()
|
ScalarType Length() const
|
||||||
{ return (_p0 - _p1).Norm(); }
|
{ return (_p0 - _p1).Norm(); }
|
||||||
/// return segment squared lenght
|
/// return segment squared lenght
|
||||||
ScalarType SquaredLength()
|
ScalarType SquaredLength() const
|
||||||
{ return (_p0 - _p1).SquaredNorm(); }
|
{ return (_p0 - _p1).SquaredNorm(); }
|
||||||
/// flips: a-b becomes b-a
|
/// flips: a-b becomes b-a
|
||||||
void Flip()
|
void Flip()
|
||||||
|
|
@ -156,54 +156,54 @@ typedef Segment3<int> Segment3i;
|
||||||
typedef Segment3<float> Segment3f;
|
typedef Segment3<float> Segment3f;
|
||||||
typedef Segment3<double> Segment3d;
|
typedef Segment3<double> Segment3d;
|
||||||
|
|
||||||
/*
|
///*
|
||||||
* Computes the minimum distance between a segment and a point
|
//* Computes the minimum distance between a segment and a point
|
||||||
* @param[in] segment The input segment
|
//* @param[in] segment The input segment
|
||||||
* @param[in] p The input point
|
//* @param[in] p The input point
|
||||||
* @return The distance between the segment and the point p
|
//* @return The distance between the segment and the point p
|
||||||
*/
|
//*/
|
||||||
template < class ScalarType >
|
//template < class ScalarType >
|
||||||
ScalarType SquaredDistance(Segment3< ScalarType > &segment, Point3< ScalarType > &p)
|
//ScalarType SquaredDistance(Segment3< ScalarType > &segment, Point3< ScalarType > &p)
|
||||||
{
|
//{
|
||||||
typedef typename vcg::Point3< ScalarType > Point3t;
|
// typedef typename vcg::Point3< ScalarType > Point3t;
|
||||||
|
//
|
||||||
Point3t dir = (segment.P1()-segment.P0()).Normalize();
|
// Point3t dir = (segment.P1()-segment.P0()).Normalize();
|
||||||
ScalarType h = dir * (p-segment.P0());
|
// ScalarType h = dir * (p-segment.P0());
|
||||||
if (h<=ScalarType(0.0)) return vcg::SquaredDistance<ScalarType>(p, segment.P0());
|
// if (h<=ScalarType(0.0)) return vcg::SquaredDistance<ScalarType>(p, segment.P0());
|
||||||
else if (h>=segment.Length()) return vcg::SquaredDistance<ScalarType>(p, segment.P1());
|
// else if (h>=segment.Length()) return vcg::SquaredDistance<ScalarType>(p, segment.P1());
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
dir = segment.P0() + dir*h;
|
// dir = segment.P0() + dir*h;
|
||||||
return vcg::SquaredDistance<ScalarType>(p, dir);
|
// return vcg::SquaredDistance<ScalarType>(p, dir);
|
||||||
}
|
// }
|
||||||
}; //end of Distance method
|
//}; //end of Distance method
|
||||||
|
//
|
||||||
template <class ScalarType>
|
//template <class ScalarType>
|
||||||
Point3<ScalarType> ClosestPoint( Segment3<ScalarType> s, const Point3<ScalarType> & p)
|
//Point3<ScalarType> ClosestPoint( Segment3<ScalarType> s, const Point3<ScalarType> & p)
|
||||||
{
|
//{
|
||||||
vcg::Line3<ScalarType> l;
|
// vcg::Line3<ScalarType> l;
|
||||||
l.Set(s.P0(),s.P1()-s.P0());
|
// l.Set(s.P0(),s.P1()-s.P0());
|
||||||
l.Normalize();
|
// l.Normalize();
|
||||||
Point3<ScalarType> clos=vcg::ClosestPoint<ScalarType,true>(l,p) ;//attention to call
|
// Point3<ScalarType> clos=vcg::ClosestPoint<ScalarType,true>(l,p) ;//attention to call
|
||||||
vcg::Box3<ScalarType> b;
|
// vcg::Box3<ScalarType> b;
|
||||||
b.Add(s.P0());
|
// b.Add(s.P0());
|
||||||
b.Add(s.P1());
|
// b.Add(s.P1());
|
||||||
if (b.IsIn(clos))
|
// if (b.IsIn(clos))
|
||||||
return clos;
|
// return clos;
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
ScalarType d0=(s.P0()-p).Norm();
|
// ScalarType d0=(s.P0()-p).Norm();
|
||||||
ScalarType d1=(s.P1()-p).Norm();
|
// ScalarType d1=(s.P1()-p).Norm();
|
||||||
if (d0<d1)
|
// if (d0<d1)
|
||||||
return (s.P0());
|
// return (s.P0());
|
||||||
else
|
// else
|
||||||
return (s.P1());
|
// return (s.P1());
|
||||||
}
|
// }
|
||||||
/*ScalarType t = s.Projection(p);
|
// /*ScalarType t = s.Projection(p);
|
||||||
if (s<0) return s.P0();
|
// if (s<0) return s.P0();
|
||||||
if (s>1) return s.P0();
|
// if (s>1) return s.P0();
|
||||||
return s.P(t);*/
|
// return s.P(t);*/
|
||||||
}
|
//}
|
||||||
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue