Created
March 29, 2024 16:03
-
-
Save hariedo/fa60a3360ee7a00eec35f760c7b9c434 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Vector3[] DistributePointsOnUnitSphere(int count) | |
{ | |
Assert.IsTrue(count > 0); | |
Vector3[] points = new Vector3[count]; | |
// The Fibonacci Sphere algorithm. | |
float phi = Mathf.PI * (Mathf.Sqrt(5f) - 1f); | |
float descent = 2f / (float)(count-1); | |
for (int i = 0; i < count; i++) | |
{ | |
// calculate Y between 1 and -1 | |
float y = 1f - i * descent; | |
float radius = Mathf.Sqrt(1f - y * y); | |
float theta = phi * (float)i; | |
float x = radius * Mathf.Cos(theta); | |
float z = radius * Mathf.Sin(theta); | |
points[i] = new Vector3(x, y, z); | |
} | |
return points; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment