How to draw a ball by plot3?

25 visualizzazioni (ultimi 30 giorni)
Xizeng Feng
Xizeng Feng il 18 Feb 2022
Risposto: J. Alex Lee il 28 Ott 2022
I am learning the MATLAB,

Risposta accettata

DGM
DGM il 19 Feb 2022
Modificato: DGM il 19 Feb 2022
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

Più risposte (2)

KSSV
KSSV il 18 Feb 2022
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 Commenti
KSSV
KSSV il 19 Feb 2022
How you want to look like? What's your expectations?
Xizeng Feng
Xizeng Feng il 19 Feb 2022
like this for example.

Accedi per commentare.


J. Alex Lee
J. Alex Lee il 28 Ott 2022
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

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by