Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|cite|improve this question
You 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? – Ben Crowell Feb 19 '12 at 21:58
up vote 2 down vote accepted

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.

share|cite|improve this answer
Sampling points on a disk is easily done without rejection, by picking $\theta$ and $r^2$ uniformly in polar coordinates. See this previous answer and MathWorld on disk point picking. – Rahul Feb 19 '12 at 21:03
Yes, you're quite right of course. One advantage of generating and rejecting points is that it works for non-symmetrical bodies as well. – mrf Feb 19 '12 at 22:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.