How to draw a ball by plot3?

조회 수: 29 (최근 30일)
Xizeng Feng
Xizeng Feng 2022년 2월 18일
답변: J. Alex Lee 2022년 10월 28일
I am learning the MATLAB,

채택된 답변

DGM
DGM 2022년 2월 19일
편집: DGM 2022년 2월 19일
I choose to assume that a request to plot a solid volume with a line/point plotting tool should suggest that the usage of the term "ball" is informal and that a spherical shell is an acceptable interpretation of the wording:
nturns = 20;
pointsperturn = 50;
r = 1;
th = linspace(0,2*pi*nturns,pointsperturn*nturns);
phi = linspace(-pi/2,pi/2,pointsperturn*nturns);
[x y z] = sph2cart(th,phi,r);
plot3(x,y,z)
axis equal
grid on
  댓글 수: 1
Xizeng Feng
Xizeng Feng 2022년 2월 19일
thank you very much!

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

추가 답변 (2개)

KSSV
KSSV 2022년 2월 18일
m = 100; n = 100; p = 100 ;
[X,Y,Z] = ndgrid(-m:m,-n:n,-p:p) ;
x = X(:) ;
y = Y(:) ;
z = Z(:) ;
r = sqrt(x.^2+y.^2+z.^2) ;
idx = r <= 10 ;
plot3(x(idx),y(idx),z(idx),'.r')
axis equal
  댓글 수: 3
KSSV
KSSV 2022년 2월 19일
How you want to look like? What's your expectations?
Xizeng Feng
Xizeng Feng 2022년 2월 19일
like this for example.

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


J. Alex Lee
J. Alex Lee 2022년 10월 28일
like this? but it doesn't use plot3
[x,y,z] = sphere(64);
p = surf(x,y,z,"FaceColor","interp","EdgeColor","none");
p.CData = rand(size(p.ZData));
colormap gray
axis equal
lighting phong
camorbit(60,0)
axis off

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by