Esempio n. 1
0
        public static bool IsPointInConvexPolygon2(GeoPointsArray2 poly, ref Vector2 point)
        {
            int   n  = poly.mPointArray.Count;
            float t1 = CounterClockwiseGL0(poly.mPointArray[0], poly.mPointArray[1], point);
            float t2 = CounterClockwiseGL0(poly.mPointArray[0], poly.mPointArray[n - 1], point);

            if (t1 < -1e-5f || t2 > 1e-5f)
            {
                return(false);
            }
            int low  = 2;
            int high = n - 1;

            while (low < high)
            {
                int mid = (low + high) >> 1;
                if (CounterClockwiseGL0(poly.mPointArray[0], poly.mPointArray[mid], point) < -1e-5f)
                {
                    high = mid;
                }
                else
                {
                    low = mid + 1;
                }
            }
            float t3 = CounterClockwiseGL0(poly.mPointArray[low], poly.mPointArray[low - 1], point);

            if (t3 > 1e-5f)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
 public static PolygonDirection CalculatePolygonArea(GeoPointsArray2 poly, ref float area)
 {
     area = CalcualetArea(poly);
     if (area > 0)
     {
         return(PolygonDirection.CCW);
     }
     else
     {
         return(PolygonDirection.CW);
     }
 }
Esempio n. 3
0
        public static PolygonDirection TriangleArea2(Vector2 p1, Vector2 p2, Vector2 p3, ref float area)
        {
            GeoPointsArray2 array = new GeoPointsArray2();

            array.mPointArray.Add(p1);
            array.mPointArray.Add(p2);
            array.mPointArray.Add(p3);
            PolygonDirection dir = GeoPolygonUtils.CalculatePolygonArea(array, ref area);

            area = area < 0 ? -area : area;
            return(dir);
        }
Esempio n. 4
0
        public static GeoAABB2 CalculateAABB(GeoPointsArray2 points)
        {
            Vector2 min = points[0];
            Vector2 max = points[0];

            for (int i = 0; i < points.Count; ++i)
            {
                min = Vector2.Min(points[i], min);
                max = Vector2.Max(points[i], max);
            }
            return(new GeoAABB2(min, max));
        }
Esempio n. 5
0
        public static float CalcualetArea(GeoPointsArray2 poly)
        {
            float area  = 0.0f;
            int   count = poly.mPointArray.Count;

            for (int i = 0; i < count; ++i)
            {
                int j = (i + 1) % count;
                area += (poly[i][0] * poly[j][1]) - (poly[j][0] * poly[i][1]);
            }
            area *= 0.5f;
            return(area);
        }
Esempio n. 6
0
        public static bool IsConvexPolygon2(GeoPointsArray2 points)
        {
            int count = points.Count;

            for (int i = 0; i < points.Count; ++i)
            {
                int pre  = (i - 1 + count) % count;
                int next = (i + 1) % count;
                if (!IsConvex(points[pre], points[i], points[next]))
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 7
0
        public static bool IsPointInPolygon2(GeoPointsArray2 poly, ref Vector2 point)
        {
            bool res = false;
            int  j   = poly.Count - 1;

            for (int i = 0; i < poly.Count; i++)
            {
                if ((((poly[i][1] <= point[1]) && (point[1] < poly[j][1])) || ((poly[j][1] <= point[1]) && (point[1] < poly[i][1]))) &&
                    (point[0] < (poly[j][0] - poly[i][0]) * (point[1] - poly[i][1]) / (poly[j][1] - poly[i][1]) + poly[i][0]))
                {
                    res = !res;
                }
                j = i;
            }
            return(res);
        }
Esempio n. 8
0
        public static GeoPointsArray3 BuildConvexHull(GeoPointsArray3 points)
        {
            points.Distinct();
            GeoPlane plane = new GeoPlane(Vector3.zero, 0);

            if (IsOnSamePlane(points, ref plane))
            {
                GeoPointsArray2 point2 = new GeoPointsArray2(GeoPlaneUtils.PlaneTransformLocal(points.mPointArray, plane));
                point2 = BuildConvexHull(point2);
                return(new GeoPointsArray3(GeoPlaneUtils.PlaneTransformGlobal(point2.mPointArray, plane)));
            }
            else
            {
                return(new GeoPointsArray3(QuickHull.BuildHull(points)));
            }
        }
Esempio n. 9
0
 public static Vector2[] TangentToPolygon(Vector2 point, GeoPointsArray2 poly)
 {
     return(null);
 }
Esempio n. 10
0
 public GeoPolygonConvex2(GeoPointsArray2 poly) :
     base(poly)
 {
 }
Esempio n. 11
0
 public GeoPolygon2(GeoPointsArray2 poly)
 {
     mPolygon = poly;
     Initialize();
 }
Esempio n. 12
0
 public static GeoPointsArray2 BuildConvexHull(GeoPointsArray2 points)
 {
     points.Distinct();
     return(new GeoPointsArray2(JarvisConvex.BuildHull(points.mPointArray)));
 }