How t generate cone using scattered random point cloud?

X
Ximena · Oct 23, 2020 · 2.4K views
Question
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)
Expert Answer
Profile picture of John Williams
John Williams PhD Expert
Answered Aug 13, 2026

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
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!