MATLAB: Generate random 3D coordinates in a cylinder

3dcylinderfaqrandomrandom number generatorxyz

I want to generate a set of 1000 3D points (x,y,z) which are located inside a cylinder of radius r and centre axis from [x1,y1,z1] to [x2,y2,z2]. Any ideas?

Best Answer

Roger Stafford's code in the FAQ for getting random points in a circle will be easy to modify. http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_set_of_random_locations_within_a_circle.3F
Simply add a random variable for the height (Z) direction.