Mercurial > octave-nkf
comparison scripts/plot/ellipsoid.m @ 7305:84a2e24c75c8
[project @ 2007-12-12 16:45:02 by jwe]
author | jwe |
---|---|
date | Wed, 12 Dec 2007 16:45:02 +0000 |
parents | |
children | e1e9bb54a440 |
comparison
equal
deleted
inserted
replaced
7304:ad066356989b | 7305:84a2e24c75c8 |
---|---|
1 ## Copyright (C) 2007 Sylvain Pelissier <sylvain.pelissier@gmail.com> | |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
16 | |
17 ## -*- texinfo -*- | |
18 ## @deftypefn {Function File} {[@var{x}, @var{y}, @var{z}] =} ellipsoid (@var{xc},@var{yc}, @var{zc}, @var{xr}, @var{yr}, @var{zr}, @var{n}) | |
19 ## @deftypefnx {Function File} {} ellipsoid (@var{h}, @dots{}) | |
20 ## Generates three matrices in @code{meshgrid} format, of an ellipsoid. | |
21 ## Called with no return arguments, @code{ellipsoid} calls directly | |
22 ## @code{surf (@var{x}, @var{y}, @var{z})}. If an axes handle is passed | |
23 ## as the first argument, the the surface is plotted to this set of axes. | |
24 ## @seealso{sphere} | |
25 ## @end deftypefn | |
26 | |
27 function [xx, yy, zz] = ellipsoid(varargin) | |
28 | |
29 [h, varargin, nargin] = __plt_get_axis_arg__ ((nargout > 0), "ellipsoid", | |
30 varargin{:}); | |
31 | |
32 if (nargin != 6 && nargin != 7) | |
33 print_usage (); | |
34 endif | |
35 | |
36 xc = varargin{1}; | |
37 yc = varargin{2}; | |
38 zc = varargin{3}; | |
39 xr = varargin{4}; | |
40 yr = varargin{5}; | |
41 zr = varargin{6}; | |
42 | |
43 if (nargin == 5) | |
44 n = 20; | |
45 else | |
46 n = varargin{7}; | |
47 endif | |
48 | |
49 theta = linspace (0, 2 * pi, n + 1); | |
50 phi = linspace (-pi / 2, pi / 2, n + 1); | |
51 [theta, phi] = meshgrid (theta, phi); | |
52 | |
53 x = xr .* cos (phi) .* cos (theta) + xc; | |
54 y = yr .* cos (phi) .* sin (theta) + yc; | |
55 z = zr .* sin (phi) + zc; | |
56 | |
57 if (nargout > 0) | |
58 xx = x; | |
59 yy = y; | |
60 zz = z; | |
61 else | |
62 surf (h, x, y, z); | |
63 endif | |
64 | |
65 endfunction | |
66 | |
67 %!demo | |
68 %! ellipsoid (0, 0, 1, 2, 3, 4, 20); |