How to use the patch function for a cone
Afficher commentaires plus anciens
I am trying to complete a homework assignment, but I am having trouble on the last task. I am supposed to use the patch function to create a figure of a cone. The cone has a radius of 20, has a height of 30, and comes to its peak at (0,0). Here is what i have tried:
th=0:.1:(2*pi);
r=20;
z=-30;
for i=1:length(th)
x(i)=r*cos(th(i));
y(i)=r*sin(th(i));
end
cone.vertices=[x, y, z;
0, 0, 0];
cone.faces=[1, 2];
figure(4)
ph=patch(cone);
ph.EdgeColor=[0, 0, 0];
ph.FaceColor=[.1, .5, .9];
ph.LineWidth=2;
Any help would be appreciated, Thanks!
Réponses (1)
KSSV
le 24 Avr 2017
M = 20 ; N = 50 ; % can be varied
R0 = 2 ; % Radius of cone
H = 2 ; % height of cone
m = H/R0 ;
nT = linspace(0,2*pi,M) ; % angles
nR = linspace(0,R0,M) ; % Radius
[T, R] = meshgrid(nT,nR) ;
% Convert grid to cartesian coordintes
XX = R.*cos(T) ;
YY = R.*sin(T) ;
ZZ = m*R ;
surf(XX,YY,ZZ) ;
Catégories
En savoir plus sur Polygons dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!