📄 wmldistlin3lin3.cpp
字号:
else // region 8 (corner)
{
if ( -fB0 < fA00 )
{
fT = (Real)0.0;
if ( fB0 >= (Real)0.0 )
{
fS = (Real)0.0;
fSqrDist = fC;
}
else
{
fS = -fB0/fA00;
fSqrDist = fB0*fS+fC;
}
}
else
{
fS = (Real)1.0;
fTmp = fA01+fB1;
if ( fTmp >= (Real)0.0 )
{
fT = (Real)0.0;
fSqrDist = fA00+((Real)2.0)*fB0+fC;
}
else if ( -fTmp >= fA11 )
{
fT = (Real)1.0;
fSqrDist = fA00+fA11+fC+((Real)2.0)*(fB0+fTmp);
}
else
{
fT = -fTmp/fA11;
fSqrDist = fTmp*fT+fA00+((Real)2.0)*fB0+fC;
}
}
}
}
}
else
{
if ( fT >= (Real)0.0 )
{
if ( fT <= fDet ) // region 5 (side)
{
fS = (Real)0.0;
if ( fB1 >= (Real)0.0 )
{
fT = (Real)0.0;
fSqrDist = fC;
}
else if ( -fB1 >= fA11 )
{
fT = (Real)1.0;
fSqrDist = fA11+((Real)2.0)*fB1+fC;
}
else
{
fT = -fB1/fA11;
fSqrDist = fB1*fT+fC;
}
}
else // region 4 (corner)
{
fTmp = fA01+fB0;
if ( fTmp < (Real)0.0 )
{
fT = (Real)1.0;
if ( -fTmp >= fA00 )
{
fS = (Real)1.0;
fSqrDist = fA00+fA11+fC+((Real)2.0)*(fB1+fTmp);
}
else
{
fS = -fTmp/fA00;
fSqrDist = fTmp*fS+fA11+((Real)2.0)*fB1+fC;
}
}
else
{
fS = (Real)0.0;
if ( fB1 >= (Real)0.0 )
{
fT = (Real)0.0;
fSqrDist = fC;
}
else if ( -fB1 >= fA11 )
{
fT = (Real)1.0;
fSqrDist = fA11+((Real)2.0)*fB1+fC;
}
else
{
fT = -fB1/fA11;
fSqrDist = fB1*fT+fC;
}
}
}
}
else // region 6 (corner)
{
if ( fB0 < (Real)0.0 )
{
fT = (Real)0.0;
if ( -fB0 >= fA00 )
{
fS = (Real)1.0;
fSqrDist = fA00+((Real)2.0)*fB0+fC;
}
else
{
fS = -fB0/fA00;
fSqrDist = fB0*fS+fC;
}
}
else
{
fS = (Real)0.0;
if ( fB1 >= (Real)0.0 )
{
fT = (Real)0.0;
fSqrDist = fC;
}
else if ( -fB1 >= fA11 )
{
fT = (Real)1.0;
fSqrDist = fA11+((Real)2.0)*fB1+fC;
}
else
{
fT = -fB1/fA11;
fSqrDist = fB1*fT+fC;
}
}
}
}
}
else
{
// line segments are parallel
if ( fA01 > (Real)0.0 )
{
// direction vectors form an obtuse angle
if ( fB0 >= (Real)0.0 )
{
fS = (Real)0.0;
fT = (Real)0.0;
fSqrDist = fC;
}
else if ( -fB0 <= fA00 )
{
fS = -fB0/fA00;
fT = (Real)0.0;
fSqrDist = fB0*fS+fC;
}
else
{
fB1 = -kDiff.Dot(rkSeg1.Direction());
fS = (Real)1.0;
fTmp = fA00+fB0;
if ( -fTmp >= fA01 )
{
fT = (Real)1.0;
fSqrDist = fA00+fA11+fC+((Real)2.0)*(fA01+fB0+fB1);
}
else
{
fT = -fTmp/fA01;
fSqrDist = fA00+((Real)2.0)*fB0+fC+fT*(fA11*fT+
((Real)2.0)*(fA01+fB1));
}
}
}
else
{
// direction vectors form an acute angle
if ( -fB0 >= fA00 )
{
fS = (Real)1.0;
fT = (Real)0.0;
fSqrDist = fA00+((Real)2.0)*fB0+fC;
}
else if ( fB0 <= (Real)0.0 )
{
fS = -fB0/fA00;
fT = (Real)0.0;
fSqrDist = fB0*fS+fC;
}
else
{
fB1 = -kDiff.Dot(rkSeg1.Direction());
fS = (Real)0.0;
if ( fB0 >= -fA01 )
{
fT = (Real)1.0;
fSqrDist = fA11+((Real)2.0)*fB1+fC;
}
else
{
fT = -fB0/fA01;
fSqrDist = fC+fT*(((Real)2.0)*fB1+fA11*fT);
}
}
}
}
if ( pfSegP0 )
*pfSegP0 = fS;
if ( pfSegP1 )
*pfSegP1 = fT;
return Math<Real>::FAbs(fSqrDist);
}
//----------------------------------------------------------------------------
template <class Real>
Real Wml::Distance (const Line3<Real>& rkLine0, const Line3<Real>& rkLine1,
Real* pfLinP0, Real* pfLinP1)
{
return Math<Real>::Sqrt(SqrDistance(rkLine0,rkLine1,pfLinP0,pfLinP1));
}
//----------------------------------------------------------------------------
template <class Real>
Real Wml::Distance (const Line3<Real>& rkLine, const Ray3<Real>& rkRay,
Real* pfLinP, Real* pfRayP)
{
return Math<Real>::Sqrt(SqrDistance(rkLine,rkRay,pfLinP,pfRayP));
}
//----------------------------------------------------------------------------
template <class Real>
Real Wml::Distance (const Line3<Real>& rkLine, const Segment3<Real>& rkSeg,
Real* pfLinP, Real* pfSegP)
{
return Math<Real>::Sqrt(SqrDistance(rkLine,rkSeg,pfLinP,pfSegP));
}
//----------------------------------------------------------------------------
template <class Real>
Real Wml::Distance (const Ray3<Real>& rkRay0, const Ray3<Real>& rkRay1,
Real* pfRayP0, Real* pfRayP1)
{
return Math<Real>::Sqrt(SqrDistance(rkRay0,rkRay1,pfRayP0,pfRayP1));
}
//----------------------------------------------------------------------------
template <class Real>
Real Wml::Distance (const Ray3<Real>& rkRay, const Segment3<Real>& rkSeg,
Real* pfRayP, Real* pfSegP)
{
return Math<Real>::Sqrt(SqrDistance(rkRay,rkSeg,pfRayP,pfSegP));
}
//----------------------------------------------------------------------------
template <class Real>
Real Wml::Distance (const Segment3<Real>& rkSeg0,
const Segment3<Real>& rkSeg1, Real* pfSegP0, Real* pfSegP1)
{
return Math<Real>::Sqrt(SqrDistance(rkSeg0,rkSeg1,pfSegP0,pfSegP1));
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// explicit instantiation
//----------------------------------------------------------------------------
namespace Wml
{
template WML_ITEM float SqrDistance<float> (const Line3<float>&,
const Line3<float>&, float*, float*);
template WML_ITEM float SqrDistance<float> (const Line3<float>&,
const Ray3<float>&, float*, float*);
template WML_ITEM float SqrDistance<float> (const Line3<float>&,
const Segment3<float>&, float*, float*);
template WML_ITEM float SqrDistance<float> (const Ray3<float>&,
const Ray3<float>& rkRay1, float*, float*);
template WML_ITEM float SqrDistance<float> (const Ray3<float>&,
const Segment3<float>&, float*, float*);
template WML_ITEM float SqrDistance<float> (const Segment3<float>&,
const Segment3<float>&, float*, float*);
template WML_ITEM float Distance<float> (const Line3<float>&,
const Line3<float>&, float*, float*);
template WML_ITEM float Distance<float> (const Line3<float>&,
const Ray3<float>&, float*, float*);
template WML_ITEM float Distance<float> (const Line3<float>&,
const Segment3<float>&, float*, float*);
template WML_ITEM float Distance<float> (const Ray3<float>&,
const Ray3<float>& rkRay1, float*, float*);
template WML_ITEM float Distance<float> (const Ray3<float>&,
const Segment3<float>&, float*, float*);
template WML_ITEM float Distance<float> (const Segment3<float>&,
const Segment3<float>&, float*, float*);
template WML_ITEM double SqrDistance<double> (const Line3<double>&,
const Line3<double>&, double*, double*);
template WML_ITEM double SqrDistance<double> (const Line3<double>&,
const Ray3<double>&, double*, double*);
template WML_ITEM double SqrDistance<double> (const Line3<double>&,
const Segment3<double>&, double*, double*);
template WML_ITEM double SqrDistance<double> (const Ray3<double>&,
const Ray3<double>& rkRay1, double*, double*);
template WML_ITEM double SqrDistance<double> (const Ray3<double>&,
const Segment3<double>&, double*, double*);
template WML_ITEM double SqrDistance<double> (const Segment3<double>&,
const Segment3<double>&, double*, double*);
template WML_ITEM double Distance<double> (const Line3<double>&,
const Line3<double>&, double*, double*);
template WML_ITEM double Distance<double> (const Line3<double>&,
const Ray3<double>&, double*, double*);
template WML_ITEM double Distance<double> (const Line3<double>&,
const Segment3<double>&, double*, double*);
template WML_ITEM double Distance<double> (const Ray3<double>&,
const Ray3<double>& rkRay1, double*, double*);
template WML_ITEM double Distance<double> (const Ray3<double>&,
const Segment3<double>&, double*, double*);
template WML_ITEM double Distance<double> (const Segment3<double>&,
const Segment3<double>&, double*, double*);
}
//----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -