-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsphere.m
41 lines (35 loc) · 1 KB
/
sphere.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function [xx,yy,zz] = sphere(varargin)
%SPHERE Generate sphere.
% [X,Y,Z] = SPHERE(N) generates three (N+1)-by-(N+1)
% matrices so that SURF(X,Y,Z) produces a unit sphere.
%
% [X,Y,Z] = SPHERE uses N = 20.
%
% SPHERE(N) and just SPHERE graph the sphere as a SURFACE
% and do not return anything.
%
% SPHERE(AX,...) plots into AX instead of GCA.
%
% See also ELLIPSOID, CYLINDER.
% Clay M. Thompson 4-24-91, CBM 8-21-92.
% Copyright 1984-2002 The MathWorks, Inc.
% Parse possible Axes input
narginchk(0,2);
[cax,args,nargs] = axescheck(varargin{:});
n = 20;
if nargs > 0, n = args{1}; end
% -pi <= theta <= pi is a row vector.
% -pi/2 <= phi <= pi/2 is a column vector.
theta = (-n:2:n)/n*pi;
phi = (-n:2:n)'/n*pi/2;
cosphi = cos(phi); cosphi(1) = 0; cosphi(n+1) = 0;
sintheta = sin(theta); sintheta(1) = 0; sintheta(n+1) = 0;
x = cosphi*cos(theta);
y = cosphi*sintheta;
z = sin(phi)*ones(1,n+1);
if nargout == 0
cax = newplot(cax);
surf(x,y,z,'parent',cax)
else
xx = x; yy = y; zz = z;
end