Ejemplo n.º 1
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 }
            });
        }