Esempio n. 1
0
        public static Mesh DelaunayMesh2(List <Point3d> pts)
        {
            //convert point3d to node2
            //grasshopper requres that nodes are saved within a Node2List for Delaunay
            // pts = DeepCopy(pts);
            var nodes = new Grasshopper.Kernel.Geometry.Node2List();

            foreach (Point3d pt in pts)
            {
                nodes.Append(new Grasshopper.Kernel.Geometry.Node2(pt.X, pt.Y));
            }

            //solve Delaunay
            var delMesh2d = new Mesh();
            var delMesh3d = new Mesh();
            var faces     = new List <Grasshopper.Kernel.Geometry.Delaunay.Face>();

            faces = Grasshopper.Kernel.Geometry.Delaunay.Solver.Solve_Faces(nodes, 1);

            //output
            delMesh2d = Grasshopper.Kernel.Geometry.Delaunay.Solver.Solve_Mesh(nodes, 1, ref faces);

            delMesh2d.Compact();
            delMesh3d.Faces.AddFaces(delMesh2d.Faces);
            delMesh3d.Vertices.AddVertices(pts);

            delMesh3d.Compact();
            return(delMesh3d);
        }
        public List <Grasshopper.Kernel.Geometry.Voronoi.Cell2> GetVoronoiCells(List <Point3d> pts, Brep b)
        {
            Surface fa = b.Faces[0].ToNurbsSurface();

            List <Point2d> uvs = new List <Point2d>();

            foreach (Point3d p in pts)
            {
                double u;
                double v;
                fa.ClosestPoint(p, out u, out v);
                uvs.Add(new Point2d(u, v));
            }
            var nodes = new Grasshopper.Kernel.Geometry.Node2List();

            foreach (Point2d p in uvs)
            {
                nodes.Append(new Grasshopper.Kernel.Geometry.Node2(p.X, p.Y));
            }

            var outline = new Grasshopper.Kernel.Geometry.Node2List();

            for (int i = 0; i < b.Vertices.Count; ++i)
            {
                double u;
                double v;
                fa.ClosestPoint(b.Vertices[i].Location, out u, out v);
                outline.Append(new Grasshopper.Kernel.Geometry.Node2(u, v));
            }

            return(Grasshopper.Kernel.Geometry.Voronoi.Solver.Solve_BruteForce(nodes, outline));
        }
        private void MakeGSAMesh()
        {
            GSAmesh = new Mesh();
            //convert point3d to node2
            //grasshopper requres that nodes are saved within a Node2List for Delaunay
            var node2s = new Grasshopper.Kernel.Geometry.Node2List();

            for (int i = 0; i < nodes.Count; i++)
            {
                //map nodes onto the mid plane
                Point3d mappedPt = new Point3d();
                midPlane.RemapToPlaneSpace(nodes[i], out mappedPt);
                node2s.Append(new Grasshopper.Kernel.Geometry.Node2(mappedPt.X, mappedPt.Y));
                GSAmesh.Vertices.Add(nodes[i]);
            }
            //solve Delaunay
            var delMesh = new Mesh();
            var faces   = new List <Grasshopper.Kernel.Geometry.Delaunay.Face>();

            faces = Grasshopper.Kernel.Geometry.Delaunay.Solver.Solve_Faces(node2s, 1);

            //output in 2d
            delMesh = Grasshopper.Kernel.Geometry.Delaunay.Solver.Solve_Mesh(node2s, 1, ref faces);
            if (delMesh != null)
            {
                foreach (MeshFace f in delMesh.Faces)
                {
                    GSAmesh.Faces.AddFace(f);
                }
            }
        }
Esempio n. 4
0
        //get deluanay mesh from points
        public static Mesh pointsToDeluanayMesh(List <Point3d> pts)
        {
            //convert point3d to node2
            //grasshopper requres that nodes are saved within a Node2List for Delaunay
            Plane fitPlane = new Plane();

            Plane.FitPlaneToPoints(pts, out fitPlane);
            var nodes = new Grasshopper.Kernel.Geometry.Node2List();

            for (int i = 0; i < pts.Count; i++)
            {
                double x, y = new double();
                fitPlane.ClosestParameter(pts[i], out x, out y);
                nodes.Append(new Grasshopper.Kernel.Geometry.Node2(x, y));
            }

            //solve Delaunay
            Mesh delMesh = new Mesh();
            var  faces   = new List <Grasshopper.Kernel.Geometry.Delaunay.Face>();

            faces = Grasshopper.Kernel.Geometry.Delaunay.Solver.Solve_Faces(nodes, 1);

            //output
            delMesh = Grasshopper.Kernel.Geometry.Delaunay.Solver.Solve_Mesh(nodes, 1, ref faces);
            for (int i = 0; i < delMesh.Vertices.Count; i++)
            {
                delMesh.Vertices.SetVertex(i, pts[i].X, pts[i].Y, pts[i].Z);
            }
            return(delMesh);
        }
Esempio n. 5
0
        public static Mesh DelaunayMesh(List <Point3d> points)
        {
            var nodes = new Grasshopper.Kernel.Geometry.Node2List();

            for (int i = 0; i < points.Count; i++)
            {
                nodes.Append(new Grasshopper.Kernel.Geometry.Node2(points[i].X, points[i].Y));  //notice how we only read in the X and Y coordinates, this is why points should be mapped onto the XY plane
            }
            var  faces   = Grasshopper.Kernel.Geometry.Delaunay.Solver.Solve_Faces(nodes, 1);
            Mesh delMesh = Grasshopper.Kernel.Geometry.Delaunay.Solver.Solve_Mesh(nodes, 1, ref faces);

            return(delMesh);
        }
Esempio n. 6
0
        public bool isHullVertice(int t, Polyline pl)
        {
            Grasshopper.Kernel.Geometry.Node2List list2 = new Grasshopper.Kernel.Geometry.Node2List();
            List <int> hull = new List <int>();

            for (int i = 0; i < pl.Count; i++)
            {
                Grasshopper.Kernel.Geometry.Node2 node = new Grasshopper.Kernel.Geometry.Node2(pl[i].X, pl[i].Y);
                list2.Append(node);
            }
            Grasshopper.Kernel.Geometry.ConvexHull.Solver.Compute(list2, hull);
            return(hull.Contains(t));
        }
            public void intersect(Plane p)
            {
                for (int i = 0; i < pts.Count; i++)
                {
                    double db = p.DistanceTo(pts[i].pos);
                    if (Math.Abs(db) < RhinoDoc.ActiveDoc.ModelAbsoluteTolerance)
                    {
                        pts[i].condition = 1;
                    }
                    else if (db > 0)
                    {
                        pts[i].condition = 2;
                    }
                    else if (db < 0)
                    {
                        pts[i].condition = 0;
                    }
                }
                ///////////////////////
                int ii = 0;

                while (ii < edges.Count)
                {
                    if (edges[ii].p1.condition == 0 && edges[ii].p2.condition == 0)
                    {
                        edges.RemoveAt(ii);
                    }
                    else if (edges[ii].p1.condition == 1 && edges[ii].p2.condition == 0)
                    {
                        edges.RemoveAt(ii);
                    }
                    else if (edges[ii].p1.condition == 1 && edges[ii].p2.condition == 1)
                    {
                        edges.RemoveAt(ii);
                    }
                    else if (edges[ii].p1.condition == 0 && edges[ii].p2.condition == 1)
                    {
                        edges.RemoveAt(ii);
                    }
                    else if (edges[ii].p1.condition == 0 && edges[ii].p2.condition == 2)
                    {
                        double u; Line line = new Line(edges[ii].p1.pos, edges[ii].p2.pos);
                        Rhino.Geometry.Intersect.Intersection.LinePlane(line, p, out u);
                        pts.Add(new vertex(line.PointAt(u), this.center.DistanceTo(line.PointAt(u))));
                        edges[ii].p1 = pts[pts.Count - 1];
                        ii++;
                    }
                    else if (edges[ii].p1.condition == 2 && edges[ii].p2.condition == 0)
                    {
                        double u; Line line = new Line(edges[ii].p1.pos, edges[ii].p2.pos);
                        Rhino.Geometry.Intersect.Intersection.LinePlane(line, p, out u);
                        pts.Add(new vertex(line.PointAt(u), this.center.DistanceTo(line.PointAt(u))));
                        edges[ii].p2 = pts[pts.Count - 1];
                        ii++;
                    }
                    else
                    {
                        ii++;
                    }
                }
                clearnull();
                //////////////////////////////////
                Transform w2p = Transform.PlaneToPlane(Plane.WorldXY, p);
                Transform p2w = Transform.PlaneToPlane(p, Plane.WorldXY);

                Grasshopper.Kernel.Geometry.Node2List ls = new Grasshopper.Kernel.Geometry.Node2List();
                List <int> count = new List <int>();

                for (int i = 0; i < pts.Count; i++)
                {
                    if (pts[i].condition == 1 || pts[i].condition == -1)
                    {
                        pts[i].pos.Transform(w2p);
                        ls.Append(new Grasshopper.Kernel.Geometry.Node2(pts[i].pos.X, pts[i].pos.Y));
                        pts[i].pos.Transform(p2w);
                        count.Add(i);
                    }
                }
                if (count.Count == 2)
                {
                    edges.Add(new edge(pts[count[0]], pts[count[1]]));
                }
                else if (count.Count > 2)
                {
                    List <int> count2 = new List <int>();
                    Grasshopper.Kernel.Geometry.ConvexHull.Solver.Compute(ls, count2);
                    for (int i = 0; i < count2.Count; i++)
                    {
                        int c = i + 1; if (c == count2.Count)
                        {
                            c = 0;
                        }
                        edges.Add(new edge(pts[count[count2[i]]], pts[count[count2[c]]]));
                    }
                }
            }
 public bool isHullVertice(int t, Polyline pl)
 {
     Grasshopper.Kernel.Geometry.Node2List list2 = new Grasshopper.Kernel.Geometry.Node2List();
     List<int> hull = new List<int>();
     for (int i = 0; i < pl.Count; i++)
     {
         Grasshopper.Kernel.Geometry.Node2 node = new Grasshopper.Kernel.Geometry.Node2(pl[i].X, pl[i].Y);
         list2.Append(node);
     }
     Grasshopper.Kernel.Geometry.ConvexHull.Solver.Compute(list2, hull);
     return hull.Contains(t);
 }
Esempio n. 9
0
 public void intersect(Plane p)
 {
     for (int i = 0; i < pts.Count; i++)
     {
         double db = p.DistanceTo(pts[i].pos);
         if (Math.Abs(db) < RhinoDoc.ActiveDoc.ModelAbsoluteTolerance) { pts[i].condition = 1; }
         else if (db > 0) { pts[i].condition = 2; }
         else if (db < 0) { pts[i].condition = 0; }
     }
     ///////////////////////
     int ii = 0;
     while (ii < edges.Count)
     {
         if (edges[ii].p1.condition == 0 && edges[ii].p2.condition == 0)
         {
             edges.RemoveAt(ii);
         }
         else if (edges[ii].p1.condition == 1 && edges[ii].p2.condition == 0)
         {
             edges.RemoveAt(ii);
         }
         else if (edges[ii].p1.condition == 1 && edges[ii].p2.condition == 1)
         {
             edges.RemoveAt(ii);
         }
         else if (edges[ii].p1.condition == 0 && edges[ii].p2.condition == 1)
         {
             edges.RemoveAt(ii);
         }
         else if (edges[ii].p1.condition == 0 && edges[ii].p2.condition == 2)
         {
             double u; Line line = new Line(edges[ii].p1.pos, edges[ii].p2.pos);
             Rhino.Geometry.Intersect.Intersection.LinePlane(line, p, out u);
             pts.Add(new vertex(line.PointAt(u), this.center.DistanceTo(line.PointAt(u))));
             edges[ii].p1 = pts[pts.Count - 1];
             ii++;
         }
         else if (edges[ii].p1.condition == 2 && edges[ii].p2.condition == 0)
         {
             double u; Line line = new Line(edges[ii].p1.pos, edges[ii].p2.pos);
             Rhino.Geometry.Intersect.Intersection.LinePlane(line, p, out u);
             pts.Add(new vertex(line.PointAt(u), this.center.DistanceTo(line.PointAt(u))));
             edges[ii].p2 = pts[pts.Count - 1];
             ii++;
         }
         else { ii++; }
     }
     clearnull();
     //////////////////////////////////
     Transform w2p = Transform.PlaneToPlane(Plane.WorldXY, p);
     Transform p2w = Transform.PlaneToPlane(p, Plane.WorldXY);
     Grasshopper.Kernel.Geometry.Node2List ls = new Grasshopper.Kernel.Geometry.Node2List();
     List<int> count = new List<int>();
     for (int i = 0; i < pts.Count; i++)
     {
         if (pts[i].condition == 1 || pts[i].condition == -1)
         {
             pts[i].pos.Transform(w2p);
             ls.Append(new Grasshopper.Kernel.Geometry.Node2(pts[i].pos.X, pts[i].pos.Y));
             pts[i].pos.Transform(p2w);
             count.Add(i);
         }
     }
     if (count.Count == 2) edges.Add(new edge(pts[count[0]], pts[count[1]]));
     else if (count.Count > 2)
     {
         List<int> count2 = new List<int>();
         Grasshopper.Kernel.Geometry.ConvexHull.Solver.Compute(ls, count2);
         for (int i = 0; i < count2.Count; i++)
         {
             int c = i + 1; if (c == count2.Count) c = 0;
             edges.Add(new edge(pts[count[count2[i]]], pts[count[count2[c]]]));
         }
     }
 }