Example #1
0
        /// <summary>
        /// Checks if point is in polygon (two checks with two rays).
        /// </summary>
        /// <returns><c>true</c>, if point is in polygon, <c>false</c> otherwise.</returns>
        /// <param name="polygon">Polygon.</param>
        /// <param name="CurrentPosition">Current position.</param>
        public bool IsInPolygon(Polygon polygon, Location CurrentPosition)
        {
            LineEntity F1 = new LineEntity(polygon.Positions[0], polygon.Positions[1]);
            LineEntity F2 = new LineEntity(polygon.Positions[1], polygon.Positions[2]);
            LineEntity F3 = new LineEntity(polygon.Positions[2], polygon.Positions[3]);
            LineEntity F4 = new LineEntity(polygon.Positions[3], polygon.Positions[0]);

            // The end of first ray
            Position B = new Position(CurrentPosition.Longitude + 34.282828, CurrentPosition.Latitude + 83.181772626);
            // The end of second ray
            Position C = new Position(CurrentPosition.Longitude + 23.2828828, CurrentPosition.Latitude + 12.001827);

            LineEntity AB = new LineEntity(CurrentPosition, B);
            LineEntity AC = new LineEntity(CurrentPosition, C);


            int ABCounter = 0;

            if (lineInteractor.IfIntersect(AB, F1))
            {
                ABCounter++;
            }
            if (lineInteractor.IfIntersect(AB, F2))
            {
                ABCounter++;
            }
            if (lineInteractor.IfIntersect(AB, F3))
            {
                ABCounter++;
            }
            if (lineInteractor.IfIntersect(AB, F4))
            {
                ABCounter++;
            }

            int ACCounter = 0;

            if (lineInteractor.IfIntersect(AC, F1))
            {
                ACCounter++;
            }
            if (lineInteractor.IfIntersect(AC, F2))
            {
                ACCounter++;
            }
            if (lineInteractor.IfIntersect(AC, F3))
            {
                ACCounter++;
            }
            if (lineInteractor.IfIntersect(AC, F4))
            {
                ACCounter++;
            }

            if (ABCounter % 2 == 1 && ACCounter % 2 == 1)
            {
                return(true);
            }
            return(false);
        }
Example #2
0
        /// <summary>
        /// Checks the intersect of two lines.
        /// </summary>
        /// <returns><c>true</c>, if intersect was ifed, <c>false</c> otherwise.</returns>
        /// <param name="Left">First line to check.</param>
        /// <param name="Right">Second line to check.</param>
        public bool IfIntersect(LineEntity Left, LineEntity Right)
        {
            Position A = Left.X;
            Position B = Left.Y;
            Position C = Right.X;
            Position D = Right.Y;

            return(CheckIntersect1(A.Longitude, B.Longitude, C.Longitude, D.Longitude) &&
                   CheckIntersect1(A.Latitude, B.Latitude, C.Latitude, D.Latitude) &&
                   ReturnArea(A, B, C) * ReturnArea(A, B, D) <= 0 &&
                   ReturnArea(C, D, A) * ReturnArea(C, D, B) <= 0);
        }