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!
KSSV
KSSV 2017년 4월 25일
Try:
surf(XX,YY,ZZ,0*ZZ,'edgecolor','k')

댓글을 달려면 로그인하십시오.

카테고리

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