title: Uniform sampling (by volume) within a cone
body: <p>I'm looking for an algorithm that can generate points within a cone with a flat bottom (a disk).</p>
  
  <p>I have the normalized axis along which the cone is being created (for our purposes let's just say it is the y-axis so (0, 1, 0) and the angle of the cone (let's say it is 45 degrees). </p>
  
  <p>The only resources I could find online generate vectors within a cone, but they are based on sampling a sphere, so at the bottom you get a kind of "snow-cone" effect instead of a disk at the bottom.</p>
  
  <p>That is done with the following pseudocode:</p>
  
  <pre><code>// Sample phi uniformly on [0, 2PI]
  float phi = rand(0, 1) * 2 * PI
  
  // Sample u uniformly from [cos(angle), 1]
  float u = rand(0, 1) * (1 - cos(angle * PI/180)) + cos(angle * PI/180)
  
  vec3 = vec3(sqrt(1 - u^2) * cos(phi), u, sqrt(1 - u^2) * sin(phi)))
  </code></pre>
  
  <p>The below picture is what I am going for. Having the ability to generate samples either on the surface or inside would be nice as well:</p>
  
  <p><a href="https://i.stack.imgur.com/CGGJD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CGGJD.jpg" alt="enter image description here"></a></p>