Esempio n. 1
0
        private void DrawPolygonClip(PaintEventArgs e)
        {
            var aPoint1 = new GeoCoordinate(20.0, 20.0, 0.0);
            var aPoint2 = new GeoCoordinate(30.0, 200.0, 0.0);
            var aPoint3 = new GeoCoordinate(100.0, 300.0, 0.0);
            var aPoint4 = new GeoCoordinate(400.0, 350.0, 0.0);
            var aPoint5 = new GeoCoordinate(350.0, 150.0, 0.0);

            var aPolyline = new GeoPolyline();

            aPolyline.addVertex(aPoint1);
            aPolyline.addVertex(aPoint2);
            aPolyline.addVertex(aPoint3);
            aPolyline.addVertex(aPoint4);
            aPolyline.addVertex(aPoint5);
            aPolyline.close();

            var aPolygon = new GeoPolygon();

            aPolygon.setPolyline(aPolyline);

            DrawPolygon(e, aPolygon, Color.FromArgb(255, 0, 0, 255));

            var aNormal = new GeoNormal(1, 1, 0);

            var aPlane = new GeoPlane(aNormal, 3.0 * trackBar1.Value + 100.0);

            var aClippedPolygon = aPolygon.clip(aPlane);

            DrawPolygon(e, aClippedPolygon, Color.FromArgb(255, 255, 0, 0));
        }
Esempio n. 2
0
        public static bool IsOnSamePlane(GeoPointsArray3 points, ref GeoPlane plane)
        {
            if (points.Size() < 4)
            {
                return(true);
            }
            int     count = points.Size();
            int     i     = 2;
            Vector3 p     = points[0];

            for (; i < count; ++i)
            {
                p = points[i];
                if (!GeoLineUtils.IsPointInLine3(points[0], points[1], ref p))
                {
                    break;
                }
            }
            if (i == count)
            {
                return(true);
            }
            plane = GeoPlaneUtils.CreateFromTriangle(points[0], points[1], p);
            i     = 2;
            int c = 2;

            for (; i < count; ++i)
            {
                if (GeoPlaneUtils.IsPointOnPlane(plane.mNormal, plane.mD, points[i]))
                {
                    c++;
                }
            }
            return(c == count);
        }
Esempio n. 3
0
        public QHullTrianglePlane(Vector3 a, Vector3 b)
        {
            Vector3 normal = Vector3.Cross(b - a, Vector3.forward);

            normal.Normalize();
            float d = -Vector3.Dot(normal, a);

            mPlane           = new GeoPlane(normal, d);
            mVertexPoints    = new Vector3[3];
            mVertexPoints[0] = a;
            mVertexPoints[1] = b;
            mVertexPoints[2] = Vector3.zero;
        }
Esempio n. 4
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)));
            }
        }