Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate random points on a surface of the cylinder

Tags:

python

I want to generate random points on the surface of cylinder such that distance between the points fall in a range of 230 and 250. I used the following code to generate random points on surface of cylinder:

import random,math
H=300
R=20
s=random.random()
#theta = random.random()*2*math.pi
for i in range(0,300):
    theta = random.random()*2*math.pi
    z = random.random()*H
    r=math.sqrt(s)*R
    x=r*math.cos(theta)
    y=r*math.sin(theta)
    z=z
    print 'C'  , x,y,z

How can I generate random points such that they fall with in the range(on the surfaceof cylinder)?

like image 610
user1407199 Avatar asked Nov 03 '22 00:11

user1407199


1 Answers

This is not a complete solution, but an insight that should help. If you "unroll" the surface of the cylinder into a rectangle of width w=2*pi*r and height h, the task of finding distance between points is simplified. You have not explained how to measure "distance along the surface" between points on the top of the cylinder and the side- this is a slightly tricky bit of geometry.

As for computing the distance along the surface when we created an artificial "seam", just use both (x1-x2) and (w -x1+x2) - whichever gives the shorter distance is the one you want.

I do think that @VincentNivoliers' suggestion to use Poisson disk sampling is very good, but with the constraints of h=300 and r=20 you will get terrible results no matter what.

like image 142
Floris Avatar answered Nov 08 '22 04:11

Floris