How to draw a ball by plot3?

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by