How to use the patch function for a cone

10 ビュー (過去 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 Center および File ExchangePolygons についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by