How to use the patch function for a cone

10 views (last 30 days)
ckc
ckc on 23 Apr 2017
Commented: KSSV on 25 Apr 2017
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!

Answers (1)

KSSV
KSSV on 24 Apr 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) ;
  2 Comments
ckc
ckc on 24 Apr 2017
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!
KSSV
KSSV on 25 Apr 2017
Try:
surf(XX,YY,ZZ,0*ZZ,'edgecolor','k')

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!