Esempio n. 1
0
        /// <summary>
        /// Splits a surface by multiple curves.
        /// </summary>
        /// <param name="srf"></param>
        /// <param name="crvs"></param>
        /// <search></search>
        public static Autodesk.DesignScript.Geometry.Geometry[] SplitPlanarSurfaceByMultipleCurves(this Autodesk.DesignScript.Geometry.Surface srf, List <Autodesk.DesignScript.Geometry.Curve> crvs)
        {
            Autodesk.DesignScript.Geometry.Vector vec = srf.NormalAtParameter(0.5, 0.5);

            List <Autodesk.DesignScript.Geometry.Surface> srfLst = new List <Autodesk.DesignScript.Geometry.Surface>();

            foreach (Autodesk.DesignScript.Geometry.Curve crv in crvs)
            {
                Autodesk.DesignScript.Geometry.Surface splitSrf = crv.Extrude(vec, 5000);
                srfLst.Add(splitSrf);
            }

            Autodesk.DesignScript.Geometry.PolySurface polysrf = Autodesk.DesignScript.Geometry.PolySurface.ByJoinedSurfaces(srfLst);

            Autodesk.DesignScript.Geometry.Geometry[] geo = srf.Split(polysrf);

            vec.Dispose();
            polysrf.Dispose();
            foreach (Autodesk.DesignScript.Geometry.Surface s in srfLst)
            {
                s.Dispose();
            }

            return(geo);
        }
Esempio n. 2
0
        public static object AwareTributaryArea_ByPoints(Dyn.Surface boundarySrf, List <Dyn.Point> pointsForLoad, bool flipDirection)
        {
            sDynamoConverter dycon = new sDynamoConverter("Feet", "Meters");

            List <Dyn.UV> uvs = new List <Dyn.UV>();


            //double fac = 10;
            //if (flipDirection) fac *= -1;
            //foreach (Dyn.Curve seg in Dyn.PolyCurve.ByJoinedCurves(boundarySrf.PerimeterCurves()).Offset(fac).Explode())
            //{
            //    uvs.Add(boundarySrf.UVParameterAtPoint(seg.PointAtParameter(0.5)));
            //}
            foreach (Dyn.Point lp in pointsForLoad)
            {
                uvs.Add(boundarySrf.UVParameterAtPoint(lp));
            }
            List <Dyn.Surface> vorocut = new List <Dyn.Surface>();

            foreach (var vc in Voronoi.ByParametersOnSurface(uvs, boundarySrf))
            {
                Dyn.Curve vcc = vc as Dyn.Curve;

                Dyn.Geometry[] ints = boundarySrf.Intersect(vcc);
                if (ints != null && ints.Length > 0)
                {
                    for (int i = 0; i < ints.Length; ++i)
                    {
                        if (ints[i] is Dyn.Curve)
                        {
                            Dyn.Curve   ic   = ints[i] as Dyn.Curve;
                            Dyn.Surface isrf = ic.Extrude(Dyn.Vector.ZAxis().Scale(5));
                            vorocut.Add(isrf);
                        }
                        else
                        {
                            object t = ints[i];
                        }
                    }
                }
            }
            List <Dyn.Surface> voroPattern = new List <Dyn.Surface>();
            List <double>      voroArea    = new List <double>();
            List <Dyn.Point>   lpts        = new List <Dyn.Point>();

            Dyn.PolySurface vorocutPoly = Dyn.PolySurface.ByJoinedSurfaces(vorocut);
            Dyn.Geometry[]  splited     = boundarySrf.Split(vorocutPoly);
            for (int i = 0; i < splited.Length; ++i)
            {
                Dyn.Surface vsrf = splited[i] as Dyn.Surface;
                if (vsrf != null)
                {
                    //voroPattern.Add(Dyn.PolyCurve.ByJoinedCurves(vsrf.PerimeterCurves()));
                    voroPattern.Add(vsrf);
                    voroArea.Add(vsrf.Area);

                    foreach (Dyn.Point lp in pointsForLoad)
                    {
                        if (lp.DistanceTo(vsrf) < 0.005)
                        {
                            lpts.Add(lp);
                            break;
                        }
                    }
                }
            }


            //vorocutPoly.Dispose();

            return(new Dictionary <string, object>
            {
                { "LoadPoints", lpts },
                { "TributaryAreaSrfs", voroPattern },
                { "TributaryArea", voroArea }
            });
        }