Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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|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

1 Answer 1

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|improve this answer
1  
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

 
discard

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.