How to use the patch function for a cone

6 次查看(过去 30 天)
ckc
ckc 2017-4-23
评论: KSSV 2017-4-25
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!

回答(1 个)

KSSV
KSSV 2017-4-24
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) ;
  2 个评论
ckc
ckc 2017-4-24
That does give the correct graph that i am looking for, except i need it to be one solid color and not have the grids. Thank you!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Polygons 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by