# How to generate random points on the surface of a quadrilateral

Alright, I'm sure there has to be a simple way to do this but it eludes me at the moment.

I want to be able to generate random points on the surface of a quadrilateral in 3D space. (Defined simply as four points) What is the best way to go about doing this?

If the quad is a rectangle, this is trivial to do with random interpolation between points. However, this won't work for me since my quads aren't guaranteed to have rectangular properties.

Cut the quad into two trianles, get their area size, then first random-pick one of the triangles (based on their areas) and finally pick a random point in the triangle using your favourite standard algorithm for triangles.

• Accepted but you think you could point me in the right direction for handling the triangles? Commented Feb 19, 2012 at 17:53
• stackoverflow.com/questions/4778147/…
– Imi
Commented Feb 19, 2012 at 21:34

You can easily do this with a variant of bilinear interpolation. For example

Point randomInQuad(Point a, b, c, d) {
double s = random(0.0,1.0);  // uniform in [0,1]
Point e = s*a + (1-s)*b;
Point f = s*c + (1-s)*d;
double t = random(0.0,1.0);
return t*e + (1-t)*f;
}


You can interpret this as putting each of the vertices of your quad at a corner of a unit square. Then, you randomly pick a point in the unit square. Finally, you use bilinear interpolation (which is a series of affine combinations) to interpolate a vertex at that point.

• This is not uniform picking. Consider what happens when two vertices are very close to each other: you get a lot more points in that area. Commented Feb 20, 2012 at 10:38
• Also, if the quad has a concavity (a dart shape or a fold along a diagonal), this method can produce points outside the polygon(s). Commented Oct 21, 2023 at 11:04