Skip to content

Instantly share code, notes, and snippets.

@Jellonator
Created April 7, 2021 05:16
Show Gist options
  • Save Jellonator/18e6fce8f42576b2dc5205e6849a60af to your computer and use it in GitHub Desktop.
Save Jellonator/18e6fce8f42576b2dc5205e6849a60af to your computer and use it in GitHub Desktop.
func gen_random_in_cone(theta: float) -> Vector3:
var z = rand_range(cos(theta), 1.0)
var phi = rand_range(0.0, PI * 2.0)
var tmp = sqrt(1 - z*z)
return Vector3(tmp * cos(phi), tmp * sin(phi), z)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment