MATLAB: How t generate cone using scattered random point cloud

computer visionimage processingmathematicsMATLABmatlab function

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)

Best Answer

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
Related Question