7189
|
1 ## Copyright (C) 2007 Michael Goffioul |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2 of the License, or |
|
6 ## (at your option) any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, |
|
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 ## GNU General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this program; if not, write to the Free Software |
|
15 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
16 ## 02110-1301 USA |
|
17 |
|
18 ## -*- texinfo -*- |
|
19 ## @deftypefn {Function File} {[@var{x}, @var{y}, @var{z}] =} sphere (@var{n}) |
|
20 ## @deftypefnx {Function File} {} sphere (@var{h}, @dots{}) |
|
21 ## Generates three matrices in @code{meshgrid} format, such that |
|
22 ## @code{surf (@var{x}, @var{y}, @var{z})} generates a unit sphere. |
|
23 ## The matrices of @code{@var{n}+1}-by-@code{@var{n}+1}. If @var{n} is |
|
24 ## omitted then a default value of 20 is assumed. |
|
25 ## |
|
26 ## Called with no return arguments, @code{sphere} call directly |
|
27 ## @code{surf (@var{x}, @var{y}, @var{z})}. If an axes handle is passed |
|
28 ## as the first argument, the the surface is plotted to this set of axes. |
|
29 ## @seealso{peaks} |
|
30 ## @end deftypefn |
|
31 |
7215
|
32 function [xx, yy, zz] = sphere (varargin) |
7189
|
33 |
7215
|
34 [h, varargin, nargin] = __plt_get_axis_arg__ ((nargout > 0), "sphere", |
|
35 varargin{:}); |
|
36 if (nargin > 1) |
|
37 print_usage (); |
7191
|
38 elseif (nargin == 1) |
7215
|
39 n = varargin{1}; |
7189
|
40 else |
7191
|
41 n = 20; |
7189
|
42 endif |
|
43 |
|
44 theta = linspace (0, 2*pi, n+1); |
|
45 phi = linspace (-pi/2, pi/2, n+1); |
|
46 [theta,phi] = meshgrid (theta, phi); |
|
47 |
7191
|
48 x = cos (phi) .* cos (theta); |
|
49 y = cos (phi) .* sin (theta); |
|
50 z = sin (phi); |
7189
|
51 |
|
52 if (nargout > 0) |
|
53 xx = x; |
|
54 yy = y; |
|
55 zz = z; |
|
56 else |
7215
|
57 surf (h, x, y, z); |
7189
|
58 endif |
|
59 |
|
60 endfunction |