Computes sphere coordinates
[x, y, z] = sphere(n)
Number of faces. Default value is 20.
Can be scalar or a vector of size 1 x 2 (number of faces for longitude and latitude)
Computed coordinates returned as (n+1) x (n+1) matrices.
sphere returns the Cartesian coordinates of a sphere (without drawing it). The returned sphere has a radius equal to 1 and is centered on origin.
Sphere centered on origin with radius equal to 1:
Sphere centered on origin with radius equal to 3:
scf(); [x, y, z] = sphere(40); surf(3 * x, 3 * y, 3 * z); gcf().color_map = parula(64); gca().isoview = "on"; | ![]() | ![]() |

Sphere centered on (1,2,3) with radius equal to 1:
scf(); [x, y, z] = sphere(40); surf(x + 1, y + 2, z + 3); gcf().color_map = autumn(64); gca().isoview = "on"; | ![]() | ![]() |

Sphere centered on origin with a vector n:
scf(); [x, y, z] = sphere([20 40]); surf(x, y, z); gcf().color_map = parula(64); gca().isoview = "on"; | ![]() | ![]() |

| Version | Description |
| 2025.1.0 | Function sphere introduced. |