void Start() { // Create your sites (lets call that the center of your polygons) List <Vector2> points = CreateRandomPoint(); // Create the bounds of the voronoi diagram // Use Rectf instead of Rect; it's a struct just like Rect and does pretty much the same, // but like that it allows you to run the delaunay library outside of unity (which mean also in another tread) Rect bounds = new Rect(0, 0, 512, 512); // There is a two ways you can create the voronoi diagram: with or without the lloyd relaxation // Here I used it with 2 iterations of the lloyd relaxation Voronoi voronoi = new Voronoi(points, bounds, 2); // But you could also create it without lloyd relaxtion and call that function later if you want //Voronoi voronoi = new Voronoi(points,bounds); //voronoi.LloydRelaxation(5); // Now retreive the edges from it, and the new sites position if you used lloyd relaxtion sites = voronoi.SitesIndexedByLocation; edges = voronoi.Edges; VoronoiToGraph vtg = new VoronoiToGraph(); vtg.GeneraGrafo(edges, 512f); DisplayVoronoiDiagram(); }
private void Start() { Node exit = new Node(new Vector2(-1, -1)); vtg = new VoronoiToGraph(); //genera un immagine su cui lloyd e voronoi lavoreranno Rect bounds = new Rect(0, 0, maxCanvas, maxCanvas); //punti randomici NON QUELLI DA UTILIZZARE List <Vector2> points = CreateRandomPoint(polygonNumber); //genero voronoi e modifico tramite lloyd Voronoi voronoi = new Voronoi(points, bounds, 4); puntiLloyd = voronoi.SitesIndexedByLocation; archiDelGrafo = voronoi.Edges; vtg.GeneraGrafo(archiDelGrafo, maxCanvas); Graph grafoFinale = vtg.GetGraph(); //vtg.MergeNodes(); foreach (Node a in grafoFinale.nodes) { Debug.Log(a.position + "questo e un nodo del grafo dove x =" + a.position.x + " y =" + a.position.y); } Debug.Log(grafoFinale.nodes.Count); DisplayVoronoiDiagram(points, archiDelGrafo);//grafo voronoi poligoni = new LoopFinder(); poligoni.PolyTransform(poligono, exit); Node next = vtg.GetStartingPoint(); do { next = poligoni.FindLoops(next); } while (next != exit); foreach (Arc a in grafoFinale.arcs) { Debug.Log(a.value + "dell'arco che va da " + a.a.position + " a " + a.b.position); } //DisplayVoronoiDiagram(points, vtg.poligoni.arcs);//mio grafo //DisplayVoronoiDiagram(points, archiDelGrafo);//grafo voronoi //tBase.text = archiDelGrafo.ToString()+ ""; }