Exemple #1
0
        /**********************************************************
         * To check the Pt is in the Triangle or not.
         * If the Pt is in the line or is a vertex, then return true.
         * If the Pt is out of the Triangle, then return false.
         *
         * This method is used for triangle only.
         ***********************************************************/

        private bool TriangleContainsPoint(CPoint2D[] trianglePts, CPoint2D pt)
        {
            if (trianglePts.Length != 3)
            {
                return(false);
            }

            for (int i = trianglePts.GetLowerBound(0); i < trianglePts.GetUpperBound(0); i++)
            {
                if (pt.EqualsPoint(trianglePts[i]))
                {
                    return(true);
                }
            }

            bool bIn = false;

            CLineSegment line0 = new CLineSegment(trianglePts[0], trianglePts[1]);
            CLineSegment line1 = new CLineSegment(trianglePts[1], trianglePts[2]);
            CLineSegment line2 = new CLineSegment(trianglePts[2], trianglePts[0]);

            if (pt.InLine(line0) || pt.InLine(line1) ||
                pt.InLine(line2))
            {
                bIn = true;
            }
            else             //point is not in the lines
            {
                double dblArea0 = CPolygon.PolygonArea(new CPoint2D[] { trianglePts[0], trianglePts[1], pt });
                double dblArea1 = CPolygon.PolygonArea(new CPoint2D[] { trianglePts[1], trianglePts[2], pt });
                double dblArea2 = CPolygon.PolygonArea(new CPoint2D[] { trianglePts[2], trianglePts[0], pt });

                if (dblArea0 > 0)
                {
                    if ((dblArea1 > 0) &&
                        (dblArea2 > 0))
                    {
                        bIn = true;
                    }
                }
                else if (dblArea0 < 0)
                {
                    if ((dblArea1 < 0) &&
                        (dblArea2 < 0))
                    {
                        bIn = true;
                    }
                }
            }
            return(bIn);
        }
Exemple #2
0
        /***Check whether this line is in a longer line***/

        public bool InLine(CLineSegment longerLineSegment)
        {
            bool bInLine = false;

            if ((m_startPoint.InLine(longerLineSegment)) &&
                (m_endPoint.InLine(longerLineSegment)))
            {
                bInLine = true;
            }
            return(bInLine);
        }
Exemple #3
0
        /**********************************************************
        To check the Pt is in the Triangle or not.
        If the Pt is in the line or is a vertex, then return true.
        If the Pt is out of the Triangle, then return false.

        This method is used for triangle only.
        ***********************************************************/
        private bool TriangleContainsPoint(CPoint2D[] trianglePts, CPoint2D pt)
        {
            if (trianglePts.Length != 3) {
                return false;
            }

            for (int i = trianglePts.GetLowerBound(0); i < trianglePts.GetUpperBound(0); i++) {
                if (pt.EqualsPoint(trianglePts[i])) {
                    return true;
                }
            }

            bool bIn = false;

            CLineSegment line0 = new CLineSegment(trianglePts[0], trianglePts[1]);
            CLineSegment line1 = new CLineSegment(trianglePts[1], trianglePts[2]);
            CLineSegment line2 = new CLineSegment(trianglePts[2], trianglePts[0]);

            if (pt.InLine(line0) || pt.InLine(line1)
                || pt.InLine(line2)) {
                bIn = true;
            }
            else //point is not in the lines
            {
                double dblArea0 = CPolygon.PolygonArea(new CPoint2D[] {trianglePts[0], trianglePts[1], pt});
                double dblArea1 = CPolygon.PolygonArea(new CPoint2D[] {trianglePts[1], trianglePts[2], pt});
                double dblArea2 = CPolygon.PolygonArea(new CPoint2D[] {trianglePts[2], trianglePts[0], pt});

                if (dblArea0 > 0) {
                    if ((dblArea1 > 0)
                        && (dblArea2 > 0)) {
                        bIn = true;
                    }
                }
                else if (dblArea0 < 0) {
                    if ((dblArea1 < 0)
                        && (dblArea2 < 0)) {
                        bIn = true;
                    }
                }
            }
            return bIn;
        }