Esempio n. 1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<DHr> hours = new List<DHr>();
            String key_r = "";
            String key_a = "";
            if (DA.GetDataList(0, hours) && DA.GetData(1, ref key_r) && DA.GetData(2, ref key_a)) {

                Interval ival_r = new Interval();
                Interval ival_a = new Interval();
                float[] vals_r = new float[0];
                float[] vals_a = new float[0];

                if (!(DA.GetData(3, ref ival_r))) DHr.get_domain(key_r, hours.ToArray(), ref vals_r, ref ival_r);
                else {
                    ival_r = new Interval(hours[0].val(key_r), hours[0].val(key_r));

                    vals_r = new float[hours.Count];
                    for (int h = 0; h < hours.Count; h++) {
                        vals_r[h] = hours[h].val(key_r);
                        if (vals_r[h] < ival_r.T0) ival_r.T0 = vals_r[h];
                        if (vals_r[h] > ival_r.T1) ival_r.T1 = vals_r[h];
                    }
                }

                DHr.get_domain(key_a, hours.ToArray(), ref vals_a, ref ival_a);
                DA.GetData(4, ref ival_a);

                Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1));
                DA.GetData(5, ref plane);

                Interval ival_gr = new Interval();
                Interval ival_ga = new Interval(0, Math.PI * 2);
                DA.GetData(6, ref ival_gr);

                Interval subdivs = new Interval();
                DA.GetData(7, ref subdivs);
                int subdivs_r = (int)Math.Floor(subdivs.T0);
                int subdivs_a = (int)Math.Floor(subdivs.T1);

                List<Point3d> points = new List<Point3d>();
                for (int h = 0; h < hours.Count; h++) {
                    double radius = ival_gr.ParameterAt(ival_r.NormalizedParameterAt(vals_r[h]));
                    double theta = ival_a.NormalizedParameterAt(vals_a[h]) * Math.PI * 2;
                    Point3d gpt = PointByCylCoords(radius, theta); // a point in graph coordinates
                    hours[h].pos = gpt; // the hour records the point in graph coordinates

                    Point3d wpt = plane.PointAt(gpt.X, gpt.Y);
                    points.Add(wpt);  // adds this point in world coordinates
                }

                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Curve> regions = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Curve>();

                int segments_in_whole_circle = 36;
                //double step_r = ival_r.Length / subdivs_r;
                //double step_a = Math.PI*2 / subdivs_a;

                for (int r = 0; r < subdivs_r; r++)
                    for (int a = 0; a < subdivs_a; a++) {
                        Interval rad = new Interval(ival_gr.ParameterAt(r / (float)subdivs_r), ival_gr.ParameterAt((r + 1) / (float)subdivs_r));
                        Interval ang = new Interval(ival_ga.ParameterAt(a / (float)subdivs_a), ival_ga.ParameterAt((a + 1) / (float)subdivs_a));

                        int cnt = (int)Math.Ceiling(segments_in_whole_circle * ang.Length / Math.PI * 2);
                        Polyline pcrv = new Polyline();
                        pcrv.AddRange(FakeArc(plane, rad.T0, ang.T0, ang.T1, cnt));
                        pcrv.AddRange(FakeArc(plane, rad.T1, ang.T1, ang.T0, cnt));
                        pcrv.Add(pcrv[0]);

                        Grasshopper.Kernel.Types.GH_Curve gh_curve = new Grasshopper.Kernel.Types.GH_Curve();
                        Grasshopper.Kernel.GH_Convert.ToGHCurve(pcrv, GH_Conversion.Both, ref gh_curve);
                        regions.Append(gh_curve, new Grasshopper.Kernel.Data.GH_Path(new int[] { r, a }));
                    }

                DA.SetDataList(0, hours);
                DA.SetDataList(1, points);
                DA.SetDataTree(2, regions);

            }
        }
Esempio n. 2
0
        /// <summary>
        /// unstable method, the level is 10
        /// </summary>
        public Mesh ComputeMeshTree(List<Line> x, Point3d y,double firstEnergy,double EnergyDecrease)
        {
            Vertice1.CreateCollection(x, out this.id, out this.vs);
            for (int i = 0; i < vs.Count; i++)
            {
                if (vs[i].equalTo(y)) { vs[i].energy = firstEnergy; break; }
            }
            for (int i = 0; i < 40; i++)
            {
                vs.ForEach(delegate(Vertice1 v) { v.transferenergy(EnergyDecrease, ref vs); });
            }

            for (int i = 0; i < vs.Count; i++)
            {
                vs[i].CrateEdges(vs);
                //Print(vs[i].edges.Count.ToString());
            }
            ////////////////

            Mesh mesh = new Mesh();
            for (int i = 0; i < id.Count; i++)
            {
                Polyline pl1 = new Polyline(); Polyline pl2 = new Polyline();
                if (vs[id[i].J].refer.Count == 3)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        if (vs[id[i].J].refer[j] == id[i].I)
                        {
                            pl1 = vs[id[i].J].edges[j]; break;
                        }
                    }
                }
                if (vs[id[i].I].refer.Count == 3)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        if (vs[id[i].I].refer[j] == id[i].J)
                        {
                            pl2 = vs[id[i].I].edges[j]; break;
                        }
                    }
                }
                //Print(pl1.Count.ToString());
                if (pl1.Count == 4 && pl2.Count == 0)
                {
                    Plane p = new Plane(vs[id[i].I].pos, vs[vs[id[i].I].refer[0]].pos - vs[id[i].I].pos);
                    pl2.AddRange(pl1);
                    pl2.Transform(Transform.PlanarProjection(p));

                }
                if (pl1.Count == 0 && pl2.Count == 4)
                {
                    Plane p = new Plane(vs[id[i].J].pos, vs[vs[id[i].J].refer[0]].pos - vs[id[i].J].pos);
                    pl1.AddRange(pl2);
                    pl1.Transform(Transform.PlanarProjection(p));

                }
                if (pl1.Count == 4 && pl2.Count == 4)
                {

                    Plane p1 = new Plane(pl1[0], pl1[1], pl1[2]);
                    Plane p2 = new Plane(pl2[0], pl2[1], pl2[2]);
                    if (Vector3d.VectorAngle(p1.Normal, p2.Normal) > Math.PI / 2) pl2.Reverse();
                    mesh.Append(mc.ClosedBridge(pl1, pl2));

                }
            }

              return mesh;
        }
Esempio n. 3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<double> values = new List<double>();

            if (DA.GetDataList(0, values)) {
                bool has_colors = false;
                List<Color> colors = new List<Color>();
                has_colors = DA.GetDataList(1, colors);
                if ((has_colors) && (colors.Count != values.Count)) {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "If you're going to pass in colors, please pass in a list of colors that is the same length as the list of values you gave me.");
                    return;
                }
                Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1));
                DA.GetData(2, ref plane);

                Interval ival_gr = new Interval();
                //Interval ival_ga = new Interval(0, Math.PI * 2);
                DA.GetData(3, ref ival_gr);
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "You've set your inner or outer radius to 0.  Invalid curves will result.");

                //Interval ival_va = new Interval(0, values.Sum());

                double sum = values.Sum();
                int segments_in_whole_circle = 36;
                Interval ival_angle = new Interval(0, 0);
                List<Grasshopper.Kernel.Types.GH_Curve> regions = new List<Grasshopper.Kernel.Types.GH_Curve>();
                List<Color> colors_out = new List<Color>();
                List<Mesh> meshes = new List<Mesh>();

                for (int n = 0; n < values.Count; n++) {
                    if (values[n] == 0) continue;
                    ival_angle.T1 = ival_angle.T0 + (Math.PI * 2 / sum * values[n]);

                    int cnt = Math.Max(4, (int)Math.Ceiling(segments_in_whole_circle * ival_angle.Length / Math.PI * 2));
                    Polyline pcrv = new Polyline();
                    pcrv.AddRange(FakeArc(plane, ival_gr.T0, ival_angle.T0, ival_angle.T1, cnt));
                    pcrv.AddRange(FakeArc(plane, ival_gr.T1, ival_angle.T1, ival_angle.T0, cnt));
                    pcrv.Add(pcrv[0]);

                    Grasshopper.Kernel.Types.GH_Curve gh_curve = new Grasshopper.Kernel.Types.GH_Curve();
                    Grasshopper.Kernel.GH_Convert.ToGHCurve(pcrv, GH_Conversion.Both, ref gh_curve);
                    regions.Add(gh_curve);
                    colors_out.Add(colors[n]);

                    Rhino.Geometry.Mesh mesh = new Mesh();
                    foreach (Point3d pt in FakeArc(plane, ival_gr.T0, ival_angle.T0, ival_angle.T1, cnt)) {
                        mesh.Vertices.Add(pt);
                        if (has_colors) mesh.VertexColors.Add(colors[n]);
                    }
                    foreach (Point3d pt in FakeArc(plane, ival_gr.T1, ival_angle.T0, ival_angle.T1, cnt)) {
                        mesh.Vertices.Add(pt);
                        if (has_colors) mesh.VertexColors.Add(colors[n]);
                    }
                    for (int i = 0; i < cnt - 1; i++) {
                        mesh.Faces.AddFace(i, i + 1, i + cnt);
                        mesh.Faces.AddFace(i + 1, i + cnt + 1, i + cnt);
                    }
                    mesh.Normals.ComputeNormals();
                    mesh.Compact();
                    meshes.Add(mesh);

                    ival_angle.T0 = ival_angle.T1;
                }

                DA.SetDataList(0, regions);
                DA.SetDataList(1, meshes);
                DA.SetDataList(2, colors_out);
            }
        }
 public Mesh MeshTorus(Circle c, double t)
 {
     double cut = 64;
     List<Polyline> ls2 = new List<Polyline>();
     for (int i = 0; i < cut; i++)
     {
         List<Point3d> ls = new List<Point3d>();
         ls.Add(new Point3d(1, 0, 0));
         ls.Add(new Point3d(0.707, 0, 0.707));
         ls.Add(new Point3d(0, 0, 1));
         ls.Add(new Point3d(-0.707, 0, 0.707));
         ls.Add(new Point3d(-1, 0, 0));
         ls.Add(new Point3d(-0.707, 0, -0.707));
         ls.Add(new Point3d(0, 0, -1));
         ls.Add(new Point3d(0.707, 0, -0.707));
         Polyline l1 = new Polyline();
         l1.AddRange(ls);
         l1.Reverse();
         l1.Transform(Transform.Scale(Point3d.Origin, t));
         //l1.Transform(Transform.Translation(new Vector3d(c.Radius - t, 0, 0)));
         l1.Transform(Transform.Translation(new Vector3d(c.Radius, 0, 0)));
         l1.Transform(Transform.Rotation(Math.PI / (double)cut * 2 * i, Point3d.Origin));
         ls2.Add(l1);
     }
     Mesh mesh1 = MeshLoft(ls2, true, true);
     mesh1.Transform(Transform.PlaneToPlane(Plane.WorldXY, c.Plane));
     return mesh1;
 }