Last active
June 5, 2022 01:13
-
-
Save xetrics/b233921be54044335c00a1e5be3bf31d to your computer and use it in GitHub Desktop.
Unity Fibonacci Sphere Generation
This file contains 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
List<Vector3> FibonacciSphere(int samples) { | |
List<Vector3> list = new List<Vector3>(); | |
float phi = Mathf.PI * (3f - Mathf.Sqrt(5f)); | |
for(int i = 0; i < samples; i++) { | |
float y = 1f - (i / (float)(samples - 1)) * 2f; | |
float r = Mathf.Sqrt(1f - y * y); | |
float theta = phi * i; | |
float x = Mathf.Cos(theta) * r; | |
float z = Mathf.Sin(theta) * r; | |
list.Add(new Vector3(x, y, z)); | |
} | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment