Accelerating the pace of engineering and science

# Documentation Center

• Trial Software
• Product Updates

# sphere

Generate sphere

## 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

expand all

### Plot Sphere

Generate and plot a sphere.

```figure
sphere
```

### Plot Multiple Spheres

Define x, y, and z as coordinates of a sphere.

```[x,y,z] = sphere;
```

Plot a sphere centered at the origin. Plot two more spheres centered at (3,-2,0) and (0,1,-3).

```figure
surf(x,y,z)

hold on
surf(x+3,y-2,z); % centered at (3,-2,0)
surf(x,y+1,z-3); % centered at (0,1,-3)
```

## See Also

Was this topic helpful?