Exemplo n.º 1
0
        /// <summary>
        /// Determine whether given 2D point lies within
        /// the polygon.
        ///
        /// Written by Jeremy Tammik, Autodesk, 2009-09-23,
        /// based on code that I wrote back in 1996 in C++,
        /// which in turn was based on C code from the
        /// article "An Incremental Angle Point in Polygon
        /// Test" by Kevin Weiler, Autodesk, in "Graphics
        /// Gems IV", Academic Press, 1994.
        ///
        /// Copyright (C) 2009 by Jeremy Tammik. All
        /// rights reserved.
        ///
        /// This code may be freely used. Please preserve
        /// this comment.
        /// </summary>
        public bool PolygonContains(
            UVArray polygon,
            UV point)
        {
            // initialize
            Quadrant quad = GetQuadrant(
                polygon.get_Item(0), point);

            Quadrant angle = 0;

            // loop on all vertices of polygon
            Quadrant next_quad, delta;
            int      n = polygon.Size;

            for (int i = 0; i < n; ++i)
            {
                UV vertex = polygon.get_Item(i);

                UV next_vertex = polygon.get_Item(
                    (i + 1 < n) ? i + 1 : 0);

                // calculate quadrant and delta from last quadrant

                next_quad = GetQuadrant(next_vertex, point);
                delta     = next_quad - quad;

                AdjustDelta(
                    ref delta, vertex, next_vertex, point);

                // add delta to total angle sum
                angle = angle + delta;

                // increment for next step
                quad = next_quad;
            }

            // complete 360 degrees (angle of + 4 or -4 )
            // means inside

            return((angle == +4) || (angle == -4));

            // odd number of windings rule:
            // if (angle & 4) return INSIDE; else return OUTSIDE;
            // non-zero winding rule:
            // if (angle != 0) return INSIDE; else return OUTSIDE;
        }
Exemplo n.º 2
0
        public bool PolyGonContains(List <XYZ> xyZArray, XYZ p1)
        {
            UVArray uva = new UVArray(xyZArray);

            return(PolygonContains(uva, p1.TOUV()));
        }