Generate random 3D coordinates in a cylinder

3 views (last 30 days)
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?

Accepted Answer

Image Analyst
Image Analyst on 21 Sep 2015
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.

More Answers (1)

Vu Ngoc Quang
Vu Ngoc Quang on 18 Feb 2019
Everyone can help me
Write Matlap code that generates 3-D coordinates of 50 points (evenly distributed). These points have the same length of 26371Km. This is the first time that I learn Matlap. So please help?
  1 Comment
Image Analyst
Image Analyst on 18 Feb 2019
Edited: Image Analyst on 18 Feb 2019
What does evenly distributed mean to you? Random according to a uniform distribution (like raindrops on the ground), or in a regular grid like a rectangular grid or a honeycomb grid?
For a grid (of some kind) you could do
array3d = zeros(rows, columns, slices);
indexes = round(linspace(1, numel(array3d), 50));
array3d(indexes) = 1;

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!