Ejemplo n.º 1
0
        private void GetIntersectTypeAndOtherParameter()
        {
            switch (PositionType)
            {
            case PolygonCompareMultiPolygonPositionType.Parallel: this.IntersectType = PolygonCompareMultiPolygonIntersectType.NonIntersect; return;

            case PolygonCompareMultiPolygonPositionType.NonPlarnar: throw new Exception("Code for this case hasn't finished yet!");

            case PolygonCompareMultiPolygonPositionType.Planar:
                Polygon        surPL            = multiPolygon.SurfacePolygon;
                List <Polygon> openPLs          = multiPolygon.OpeningPolygons;
                PolygonComparePolygonResult res = new PolygonComparePolygonResult(polygon, surPL);
                switch (res.IntersectType)
                {
                case PolygonComparePolygonIntersectType.NonIntersect: this.IntersectType = PolygonCompareMultiPolygonIntersectType.NonIntersect; return;

                case PolygonComparePolygonIntersectType.Boundary: this.IntersectType = PolygonCompareMultiPolygonIntersectType.Boundary; ListLine = res.ListLine; return;

                case PolygonComparePolygonIntersectType.Point: IntersectType = PolygonCompareMultiPolygonIntersectType.Point; ListPoint = res.ListPoint; return;

                case PolygonComparePolygonIntersectType.AreaOverlap:
                    ListPolygon       = new List <Polygon>();
                    this.MultiPolygon = null;
                    foreach (Polygon pl in res.ListPolygon)
                    {
                        Polygon temp = pl;
                        foreach (Polygon openPl in multiPolygon.OpeningPolygons)
                        {
                            PolygonComparePolygonResult ppRes = new PolygonComparePolygonResult(temp, openPl);
                            if (ppRes.IntersectType == PolygonComparePolygonIntersectType.AreaOverlap)
                            {
                                object polyorMultiPolygonCut = null;
                                ppRes.GetOuterPolygon(temp, out polyorMultiPolygonCut);
                                if (polyorMultiPolygonCut == null)
                                {
                                    goto Here;
                                }
                                if (polyorMultiPolygonCut is MultiPolygon)
                                {
                                    this.MultiPolygon = polyorMultiPolygonCut as MultiPolygon;
                                    return;
                                }
                                temp = polyorMultiPolygonCut as Polygon;
                            }
                        }
                        ListPolygon.Add(temp);
                        Here : continue;
                    }
                    break;
                }
                break;
            }
        }
Ejemplo n.º 2
0
        public MultiPolygon(PlanarFace f)
        {
            List <Polygon> pls = new List <Polygon>();
            EdgeArrayArray eAA = f.EdgeLoops;

            foreach (EdgeArray eA in eAA)
            {
                List <Curve> cs = new List <Curve>();
                foreach (Edge e in eA)
                {
                    List <XYZ> points = e.Tessellate() as List <XYZ>;
                    cs.Add(Line.CreateBound(points[0], points[1]));
                }
                pls.Add(new Polygon(cs));
                if (eAA.Size == 1)
                {
                    SurfacePolygon  = pls[0];
                    OpeningPolygons = new List <Polygon>();
                    goto GetParameters;
                }
            }
            for (int i = 0; i < pls.Count; i++)
            {
                Plane plane = pls[i].Plane;
                for (int j = i + 1; j < pls.Count; j++)
                {
                    Polygon tempPoly = CheckGeometry.GetProjectPolygon(plane, pls[j]);
                    PolygonComparePolygonResult res = new PolygonComparePolygonResult(pls[i], tempPoly);
                    if (res.IntersectType == PolygonComparePolygonIntersectType.AreaOverlap)
                    {
                        if (res.ListPolygon[0] == pls[i])
                        {
                            SurfacePolygon = pls[j];
                            goto FinishLoops;
                        }
                        if (res.ListPolygon[0] == pls[j])
                        {
                            SurfacePolygon = pls[i];
                            goto FinishLoops;
                        }
                        else
                        {
                            throw new Exception("Face must contain polygons inside polygon!");
                        }
                    }
                }
            }
FinishLoops:
            if (SurfacePolygon == null)
            {
                throw new Exception("Error when retrieve surface polygon!");
            }
            Plane           = SurfacePolygon.Plane;
            OpeningPolygons = new List <Polygon>();
            foreach (Polygon pl in pls)
            {
                if (pl == SurfacePolygon)
                {
                    continue;
                }
                Polygon tempPoly = CheckGeometry.GetProjectPolygon(Plane, pl);
                OpeningPolygons.Add(tempPoly);
            }

GetParameters:
            GetParameters();
        }
Ejemplo n.º 3
0
        public static List <Curve> GetCurvesCut(Polygon mainPolygon, Polygon secPolygon)
        {
            PolygonComparePolygonResult res = new PolygonComparePolygonResult(mainPolygon, secPolygon);

            if (res.ListPolygon[0] != secPolygon)
            {
                throw new Exception("Secondary Polygon must inside Main Polygon!");
            }
            bool         isInside = true;
            List <Curve> cs       = new List <Curve>();

            foreach (Curve c in secPolygon.ListCurve)
            {
                LineComparePolygonResult lpRes = new LineComparePolygonResult(mainPolygon, CheckGeometry.ConvertLine(c));
                if (lpRes.Type == LineComparePolygonType.Inside)
                {
                    foreach (Curve c1 in mainPolygon.ListCurve)
                    {
                        LineCompareLineResult llres = new LineCompareLineResult(c, c1);
                        if (llres.Type == LineCompareLineType.SameDirectionLineOverlap)
                        {
                            goto Here;
                        }
                    }
                    cs.Add(c);
                }
                Here : continue;
            }
            isInside = false;
            foreach (Curve c in mainPolygon.ListCurve)
            {
                LineComparePolygonResult lpRes = new LineComparePolygonResult(secPolygon, CheckGeometry.ConvertLine(c));
                if (lpRes.Type == LineComparePolygonType.Outside)
                {
                    cs.Add(c);
                    continue;
                }
                foreach (Curve c1 in secPolygon.ListCurve)
                {
                    LineCompareLineResult llRes = new LineCompareLineResult(c, c1);
                    if (llRes.Type == LineCompareLineType.SameDirectionLineOverlap)
                    {
                        isInside = false;
                        if (llRes.ListOuterLine.Count == 0)
                        {
                            break;
                        }
                        foreach (Line l in llRes.ListOuterLine)
                        {
                            LineComparePolygonResult lpRes1 = new LineComparePolygonResult(secPolygon, l);
                            if (lpRes1.Type != LineComparePolygonType.Inside)
                            {
                                cs.Add(l);
                            }
                        }
                        break;
                    }
                }
            }
            if (isInside)
            {
                throw new Exception("Secondary Polygon must be tangential with Main Polygon!");
            }
            return(cs);
        }