Skip to content

Instantly share code, notes, and snippets.

@xetrics
Last active June 5, 2022 01:13
Show Gist options
  • Save xetrics/b233921be54044335c00a1e5be3bf31d to your computer and use it in GitHub Desktop.
Save xetrics/b233921be54044335c00a1e5be3bf31d to your computer and use it in GitHub Desktop.
Unity Fibonacci Sphere Generation
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