title: Uniform sampling of a triangle by dividing it into smaller parts?
body: <p>To sample a triangle ABC uniformly, I can use the following formula:</p>
  
  <p>P = (1 - sqrt(r1)) * A + (sqrt(r1)*(1 - r2)) * B + (r2*sqrt(r1)) * C</p>
  
  <p>where r1 and r2 are random numbers between 0 and 1. The more samples you take, the better. But what if I want to get a better distribution, while keeping then number of samples low?</p>
  
  <p>For example if I had a square, I can implicitly divide it into an N x N grid and generate a random sample inside the smaller grid squares. Like this:</p>
  
  <pre><code>float u = (x + rnd(seed)) / width;
  float v = (y + rnd(seed)) / height;
  </code></pre>
  
  <p>The point is I force the sampling to cover the entire grid at a lower sample resolution.</p>
  
  <p>How can I achieve this with a triangle? The only way I can think of is to explicitly subdivide it into a number of triangles using a library like <a href="https://www.cs.cmu.edu/~quake/triangle.html" rel="nofollow noreferrer">Triangle</a>. But is there a way to do this implicitly like with a square, without having to actually divide the triangle?</p>