Exemplo n.º 1
0
Real DistSegment3Box3<Real>::GetSquared ()
{
    Line3<Real> line(mSegment->Center, mSegment->Direction);
    DistLine3Box3<Real> queryLB(line, *mBox);
    Real sqrDistance = queryLB.GetSquared();
    Real lineParameter = queryLB.GetLineParameter();

    if (lineParameter >= -mSegment->Extent)
    {
        if (lineParameter <= mSegment->Extent)
        {
            mClosestPoint0 = queryLB.GetClosestPoint0();
            mClosestPoint1 = queryLB.GetClosestPoint1();
        }
        else
        {
            DistPoint3Box3<Real> queryPB(mSegment->P1, *mBox);
            sqrDistance = queryPB.GetSquared();
            mClosestPoint0 = queryPB.GetClosestPoint0();
            mClosestPoint1 = queryPB.GetClosestPoint1();
        }
    }
    else
    {
        DistPoint3Box3<Real> queryPB(mSegment->P0, *mBox);
        sqrDistance = queryPB.GetSquared();
        mClosestPoint0 = queryPB.GetClosestPoint0();
        mClosestPoint1 = queryPB.GetClosestPoint1();
    }

    return sqrDistance;
}
Exemplo n.º 2
0
Real DistRay3Box3<Real>::GetSquared ()
{
    Line3<Real> line(mRay->Origin, mRay->Direction);
    DistLine3Box3<Real> queryLB(line, *mBox);
    Real sqrDistance = queryLB.GetSquared();
    Real lineParameter = queryLB.GetLineParameter();

    if (lineParameter >= (Real)0)
    {
        mClosestPoint0 = queryLB.GetClosestPoint0();
        mClosestPoint1 = queryLB.GetClosestPoint1();
    }
    else
    {
        DistPoint3Box3<Real> queryPB(mRay->Origin, *mBox);
        sqrDistance = queryPB.GetSquared();
        mClosestPoint0 = queryPB.GetClosestPoint0();
        mClosestPoint1 = queryPB.GetClosestPoint1();
    }
    return sqrDistance;
}