コード例 #1
0
        /***Check whether this line is in a longer line***/
        public bool InLine(LineSegmentEquation longerLineSegment)
        {
            if (longerLineSegment == null)
            {
                throw new ArgumentNullException("longerLineSegment");
            }

            bool bInLine = false;

            if ((longerLineSegment.OnLine(m_startPoint)) &&
                (longerLineSegment.OnLine(m_endPoint)))
            {
                bInLine = true;
            }

            return(bInLine);
        }
コード例 #2
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(Coordinate[] trianglePts, Coordinate pt)
        {
            if (trianglePts.Length != 3)
            {
                return(false);
            }

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

            bool bIn = false;

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

            if (line0.OnLine(pt) || line1.OnLine(pt) || line2.OnLine(pt))
            {
                bIn = true;
            }
            else             //point is not in the lines
            {
                double dblArea0 = PolygonHelper.PolygonArea(
                    new Coordinate[] { trianglePts[0], trianglePts[1], pt });
                double dblArea1 = PolygonHelper.PolygonArea(
                    new Coordinate[] { trianglePts[1], trianglePts[2], pt });
                double dblArea2 = PolygonHelper.PolygonArea(
                    new Coordinate[] { 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);
        }