Skip to Main Content Skip to Search
Product Documentation

sphere - Generate sphere

Example of sphere function output

Syntax

sphere
sphere(n)
[X,Y,Z] = sphere(n)

Description

The sphere function generates the x-, y-, and z-coordinates of a unit sphere for use with surf and mesh.

sphere generates a sphere consisting of 20-by-20 faces.

sphere(n) draws a surf plot of an n-by-n sphere in the current figure.

[X,Y,Z] = sphere(n) returns the coordinates of a sphere in three matrices that are (n+1)-by-(n+1) in size. You draw the sphere with surf(X,Y,Z) or mesh(X,Y,Z).

Examples

Generate and plot a sphere.

figure
sphere
axis equal

 

Plot multiple spheres, translating centers away from the origin:

figure
[x,y,z] = sphere;
surf(x,y,z)  % sphere centered at origin
hold on
surf(x+3,y-2,z)  % sphere centered at (3,-2,0)
surf(x,y+1,z-3)  % sphere centered at (0,1,-3)
daspect([1 1 1])

See Also

axis | cylinder

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS