[X,Y,Z] = sphere returns the x-,
y-, and z- coordinates of a sphere
without drawing it. The returned sphere has a radius equal to
1 and consists of 20-by-20 faces.
The function returns the x-, y-, and
z- coordinates as three
To draw the sphere using the returned coordinates, use the
Display Unit Sphere
Create and plot a sphere with a radius equal to 1. Use
axis equal to use equal data units along each coordinate direction.
sphere axis equal
Specify Sphere Radius and Location
Specify the radius and location of a sphere by modifying the returned
Z as coordinates of a unit sphere.
[X,Y,Z] = sphere;
Plot the unit sphere centered at the origin.
surf(X,Y,Z) axis equal
Z2 as coordinates of a sphere with a radius of 5 by multiplying the coordinates of the unit sphere. Plot the second sphere, centering it at
hold on r = 5; X2 = X * r; Y2 = Y * r; Z2 = Z * r; surf(X2+5,Y2-5,Z2)
Display Sphere with Different Numbers of Faces
tiledlayout function to create a 2-by-2 tiled chart layout. Call the
nexttile function to create the axes. Then, use the
sphere function to plot three spheres with different numbers of faces into different tiles of the chart by specifying the axes.
tiledlayout(2,2); ax1 = nexttile; sphere(ax1); axis equal title('20-by-20 faces (Default)') ax2 = nexttile; sphere(ax2,50) axis equal title('50-by-50 faces') ax3 = nexttile; sphere(ax3,100) axis equal title('100-by-100 faces')
n — Number of faces
Number of faces, specified as a positive integer.
ax — Target axes
Target axes, specified as an
Axes object. If you do not
specify the axes, then
sphere plots into the current
Introduced before R2006a