Skip to content

Instantly share code, notes, and snippets.

@LeonBaudouin
Created October 29, 2021 11:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeonBaudouin/b18018da7706c6ab812e058005487980 to your computer and use it in GitHub Desktop.
Save LeonBaudouin/b18018da7706c6ab812e058005487980 to your computer and use it in GitHub Desktop.
const randomVectorInCone = (theta: number, target: THREE.Vector3) => {
const z = remap(Math.random(), [0, 1], [Math.cos(theta), 1])
const phi = remap(Math.random(), [0, 1], [0, 2 * Math.PI])
target.set(
Math.sqrt(1 - z * z) * Math.cos(phi),
Math.sqrt(1 - z * z) * Math.sin(phi),
z
)
target.normalize()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment