- Home /
How to connect generated points on a sphere?
I want to implement a A* algorithm in my game, which takes place on a planet. I generated evenly distributed points with the Code below and my wish is to create connections between a point and about 3-5 others points. One connection ist going to be a possible path with a weight, which is it's distance. I need to connect all Points in a way(maybe the neares Points?), so i can pathfind from any point to any others point in the sphere.
Vector3[] GetPointsOnSphere(int nPoints) { float fPoints = (float)nPoints; Vector3[] points = new Vector3[nPoints]; float inc = Mathf.PI * (3 - Mathf.Sqrt(5)); float off = 2 / fPoints; for (int k = 0; k < nPoints; k++) { float y = k * off - 1 + (off / 2); float r = Mathf.Sqrt(1 - y * y); float phi = k * inc; points[k] = new Vector3(Mathf.Cos(phi) * r, y, Mathf.Sin(phi) * r); } return points; }
Any ideas how to do this?
You could use debug.drawline or shoot a raycast from one point to the other and draw the raycast. Im not sure though exactly whats the best way of doing this.
What you are looking for is the Delaunay triangulation, and perhaps its counterpart the Voronoi diagram. There exists plenty of code and pre-compiled programs to calculate these polygon sets.