I have a finite cylinder in three-dimensions with a long-axis defined by the endpoints $p_1$ and $p_2$, and radius $R$. What is an easy method of picking a random point in this cylinder with uniform probability across its volume?
Generating a random point in the volume of a finite cylinder
2
$\begingroup$
geometry
-
0You can rotate into and out of a new set of coordinates aligned with the axis, but this would most likely be *less* efficient than sampling and rejection, since the change of coordinates would probably involve 10 or 20 arithmetic operations per sample. Why do you not want to use sampling and rejection? – 2012-02-19
1 Answers
2
Find a small box containing your cylinder and generate random points uniformly in the box, rejecting points that are outside the cylinder. (This is not the fastest method, but probably the simplest.)
Another method that is a little faster would be: Generate points uniformly and randomly on a disc with the same radius as your cylinder (for example as above), and then choose the distance along the axis uniformly.
-
0Yes, you're quite right of course. One advantage of generating and rejecting points is that it works for non-symmetrical bodies as well. – 2012-02-19