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)

3 件のコメント

M.S. Khan
M.S. Khan 2020 年 10 月 20 日
Dear KSSV, thanks for your kind reply. This code provides cone also but not random scattered point cloud. Regards
M.S. Khan
M.S. Khan 2020 年 10 月 20 日
They are using grid that means its uniform spaced points? Could you guide me how to generate cone using scattered random point cloud.

サインインしてコメントする。

 採用された回答

Bruno Luong
Bruno Luong 2020 年 10 月 20 日
編集済み: Bruno Luong 2020 年 10 月 20 日

1 投票

This code provides the uniform distribution on the surface of the cone
h = 3; % height
r = 1; % base radius
n = 1e4; % number of points
topcapflag = true; % include the top cap or not
rho = sqrt(rand(1,n));
z = h*rho;
if topcapflag
z(rand(1,n)<r/(h+r))=h;
end
theta = (2*pi)*rand(1,n);
rho = r*rho;
x = cos(theta).*rho;
y = sin(theta).*rho;
% graphic check
figure
plot3(x,y,z,'.')
axis equal

1 件のコメント

M.S. Khan
M.S. Khan 2020 年 10 月 21 日
Thanks Dearest Bruno for your professional supprot. Regards!

サインインしてコメントする。

その他の回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 10 月 20 日

1 投票

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
M.S. Khan 2020 年 10 月 20 日
Thanks Dear Ameer Hamza. This code sounds very helpful. Could you please explain it please. This will provide the skin of the cone, right.
Ameer Hamza
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
M.S. Khan 2020 年 10 月 21 日
Thanks Ameer Hamza,
what is the role of interpolation function here? plz explain
r = interp1([0 h], [0 r], z);
M.S. Khan
M.S. Khan 2020 年 10 月 21 日
rand() function is giving uniformly distributed numbers, right.
How is the distribution non-uniform? Pease guide, regards
Ameer Hamza
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
M.S. Khan 2020 年 10 月 21 日
How can we make text file of such point cloud?
How to combine x, y and z coordinates and save as text file.
could you please guide. i will be very thankful
Ameer Hamza
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
M.S. Khan 2020 年 10 月 21 日
Thanks Ameer Hamza. I got the idea. Regards!
Ameer Hamza
Ameer Hamza 2020 年 10 月 21 日
You can use writematrix() to write to a .txt file.
M.S. Khan
M.S. Khan 2020 年 10 月 21 日
writematrix(x(:), y(:), z(:), 'M.txt').
is it workable?
Ameer Hamza
Ameer Hamza 2020 年 10 月 21 日
No, the correct syntax is
writematrix([x(:) y(:) z(:)], 'M.txt')
M.S. Khan
M.S. Khan 2020 年 10 月 21 日
Thanks Ameer Hamza for all your kind guidance. i hope i can learn a lot from you in matlab.
Ameer Hamza
Ameer Hamza 2020 年 10 月 21 日
I am glad to be of help!
M.S. Khan
M.S. Khan 2020 年 10 月 21 日
Regards, i have sent you email by your Mathworks contact.
M.S. Khan
M.S. Khan 2021 年 3 月 4 日
Ameer Hamza, what about the cap of the cone? is it be closed or open?
anuradha verma
anuradha verma 2022 年 11 月 7 日
hello sir, can you please help me how to generate unformly distributed points inside a cone.
Bruno Luong
Bruno Luong 2022 年 11 月 7 日
編集済み: Bruno Luong 2022 年 11 月 7 日
@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
anuradha verma 2022 年 11 月 10 日
Thanks dear Bruno Luong for your kindness.With regard.
anuradha verma
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
Bruno Luong 2022 年 11 月 10 日
@anuradha verma You are off topic; since it is no longer a cone with your last question.
Please open new question and ideally stop hacking other people's question for cohesion.
anuradha verma
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
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
anuradha verma 2022 年 11 月 11 日
Thank you sir.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGeometric Transformation and Image Registration についてさらに検索

質問済み:

2020 年 10 月 20 日

コメント済み:

2022 年 11 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by