How t generate cone using scattered random point cloud?
이전 댓글 표시
Using the below code, i have geneated sphere. could anyone please guide me how to geneate cone using random scattered point cloud.
I will be very thankful. Thanks in advance to all community members for their cooperation and guidance. Regards
r = randn (10000,3);
r = round(bsxfun(@rdivide,r,sqrt(sum(r.^2,2)))*130);
x = r(:,1);
y = r(:,2);
z = r(:,3);
scatter3(x,y,z)
채택된 답변
추가 답변 (1개)
Ameer Hamza
2020년 10월 20일
This is one way. The distribution is non-uniform
h = 2; % height of cone
r = 1; % maximum radius of cross section of the cone
n = 10000;
z = rand(1, n)*h;
t = rand(1, n)*2*pi;
r = interp1([0 h], [0 r], z);
[x, y] = pol2cart(t, r);
scatter3(x, y, z)
댓글 수: 23
M.S. Khan
2020년 10월 20일
Ameer Hamza
2020년 10월 20일
First, it generates z coordinates and then, based on z value, calculates x and y coordinates that line on the circle.
M.S. Khan
2020년 10월 21일
M.S. Khan
2020년 10월 21일
Ameer Hamza
2020년 10월 21일
interp1() is a 1D interpolation. This line map value in range 0 to h, to the range 0 to r.
M.S. Khan
2020년 10월 21일
Ameer Hamza
2020년 10월 21일
Yes, rand gives uniformly distributed z coordinates. So you get an almost equal number of points for all values of z. But the circumference at the difference value of z is not the same. So at the bottom, the points are densely packed, but at the top, they have a lesser density.
M.S. Khan
2020년 10월 21일
Ameer Hamza
2020년 10월 21일
You can use writematrix() to write to a .txt file.
M.S. Khan
2020년 10월 21일
Ameer Hamza
2020년 10월 21일
No, the correct syntax is
writematrix([x(:) y(:) z(:)], 'M.txt')
M.S. Khan
2020년 10월 21일
Ameer Hamza
2020년 10월 21일
I am glad to be of help!
M.S. Khan
2020년 10월 21일
M.S. Khan
2021년 3월 4일
anuradha verma
2022년 11월 7일
hello sir, can you please help me how to generate unformly distributed points inside a cone.
@anuradha verma This code generates uniform data inside the volume of the half cone with axis parallel to z axis
Rmax = 1; % cone base radius
Zmax = 2; % cone height
N = 1e4; % Number of point
z = rand(1,N).^(1/3);
r = Rmax*sqrt(rand(1,N)).*z;
theta = (2*pi)*rand(1,N);
x = r.*cos(theta);
y = r.*sin(theta);
z = Zmax*z;
scatter3(x,y,z);
axis equal
anuradha verma
2022년 11월 10일
anuradha verma
2022년 11월 10일
Sir can you help me with the algorithm for the generation of uniformly distributed points inside the volume of a frustrum. Thanks a lot for your help.
Bruno Luong
2022년 11월 10일
Please open new question and ideally stop hacking other people's question for cohesion.
anuradha verma
2022년 11월 10일
Sir I am sorry if i have done anything wrong. I am new to matlab so i don't know much about it. Kindly forgive me.
Bruno Luong
2022년 11월 10일
편집: Bruno Luong
2022년 11월 10일
@anuradha verma, it's not difficult, if you have new question, just click on Ask, or this link:https://mathworks.com/matlabcentral/answers/questions/new
then describe the problem accurately,.
This thread is opened by the author for his problem and it's has been answered.
You question merits a new thread
anuradha verma
2022년 11월 11일
Thank you sir.
카테고리
도움말 센터 및 File Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
