コード例 #1
0
bool IntrLine2Triangle2<Real>::Find ()
{
    Real dist[3];
    int sign[3], positive, negative, zero;
    TriangleLineRelations(mLine->Origin, mLine->Direction, *mTriangle,
        dist, sign, positive, negative, zero);

    if (positive == 3 || negative == 3)
    {
        // No intersections.
        mQuantity = 0;
        mIntersectionType = IT_EMPTY;
    }
    else
    {
        Real param[2];
        GetInterval(mLine->Origin, mLine->Direction, *mTriangle, dist,
            sign, param);

        Intersector1<Real> intr(param[0], param[1],
            -Math<Real>::MAX_REAL, +Math<Real>::MAX_REAL);

        intr.Find();

        mQuantity = intr.GetNumIntersections();
        if (mQuantity == 2)
        {
            // Segment intersection.
            mIntersectionType = IT_SEGMENT;
            mPoint[0] = mLine->Origin +
                intr.GetIntersection(0)*mLine->Direction;
            mPoint[1] = mLine->Origin +
                intr.GetIntersection(1)*mLine->Direction;
        }
        else if (mQuantity == 1)
        {
            // Point intersection.
            mIntersectionType = IT_POINT;
            mPoint[0] = mLine->Origin +
                intr.GetIntersection(0)*mLine->Direction;
        }
        else
        {
            // No intersections.
            mIntersectionType = IT_EMPTY;
        }
    }

    return mIntersectionType != IT_EMPTY;
}
コード例 #2
0
bool IntrLine2Triangle2<Real>::Find ()
{
    Real afDist[3];
    int aiSign[3], iPositive, iNegative, iZero;
    TriangleLineRelations(m_pkLine->Origin,m_pkLine->Direction,*m_pkTriangle,
        afDist,aiSign,iPositive,iNegative,iZero);

    if (iPositive == 3 || iNegative == 3)
    {
        // No intersections.
        m_iQuantity = 0;
        m_iIntersectionType = IT_EMPTY;
    }
    else
    {
        Real afParam[2];
        GetInterval(m_pkLine->Origin,m_pkLine->Direction,*m_pkTriangle,afDist,
            aiSign,afParam);

        Intersector1<Real> kIntr(afParam[0],afParam[1],
            -Math<Real>::MAX_REAL,+Math<Real>::MAX_REAL);

        kIntr.Find();

        m_iQuantity = kIntr.GetQuantity();
        if (m_iQuantity == 2)
        {
            // Segment intersection.
            m_iIntersectionType = IT_SEGMENT;
            m_akPoint[0] = m_pkLine->Origin + kIntr.GetOverlap(0)*
                m_pkLine->Direction;
            m_akPoint[1] = m_pkLine->Origin + kIntr.GetOverlap(1)*
                m_pkLine->Direction;
        }
        else if (m_iQuantity == 1)
        {
            // Point intersection.
            m_iIntersectionType = IT_POINT;
            m_akPoint[0] = m_pkLine->Origin + kIntr.GetOverlap(0)*
                m_pkLine->Direction;
        }
        else
        {
            // No intersections.
            m_iIntersectionType = IT_EMPTY;
        }
    }

    return m_iIntersectionType != IT_EMPTY;
}