Mercurial > hg > octave-nkf
annotate scripts/plot/cylinder.m @ 9245:16f53d29049f
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 22 May 2009 10:46:00 -0400 |
parents | 1bf0ce0930be |
children | 95c3e38098bf |
rev | line source |
---|---|
9245 | 1 ## Copyright (C) 2007, 2009 Michael Goffioul and Kai Habel |
7181 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {} cylinder | |
21 ## @deftypefnx {Function File} {} cylinder (@var{r}) | |
22 ## @deftypefnx {Function File} {} cylinder (@var{r}, @var{n}) | |
23 ## @deftypefnx {Function File} {[@var{x}, @var{y}, @var{z}] =} cylinder (@dots{}) | |
24 ## @deftypefnx {Function File} {} cylinder (@var{ax}, @dots{}) | |
25 ## Generates three matrices in @code{meshgrid} format, such that | |
26 ## @code{surf (@var{x}, @var{y}, @var{z})} generates a unit cylinder. | |
27 ## The matrices are of size @code{@var{n}+1}-by-@code{@var{n}+1}. | |
28 ## @var{r} is a vector containing the radius along the z-axis. | |
29 ## If @var{n} or @var{r} are omitted then default values of 20 or [1 1] | |
30 ## are assumed. | |
31 ## | |
32 ## Called with no return arguments, @code{cylinder} calls directly | |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
7245
diff
changeset
|
33 ## @code{surf (@var{x}, @var{y}, @var{z})}. If an axes handle @var{ax} |
7182 | 34 ## is passed as the first argument, the surface is plotted to this set |
35 ## of axes. | |
7181 | 36 ## |
37 ## Examples: | |
38 ## @example | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
39 ## @group |
7182 | 40 ## disp ("plotting a cone") |
41 ## [x, y, z] = cylinder (10:-1:0,50); | |
42 ## surf (x, y, z); | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
43 ## @end group |
7181 | 44 ## @end example |
45 ## @seealso{sphere} | |
46 ## @end deftypefn | |
47 | |
7182 | 48 function [xx, yy, zz] = cylinder (varargin) |
7181 | 49 |
7215 | 50 [ax, args, nargs] = __plt_get_axis_arg__ ((nargout > 0), "cylinder", |
51 varargin{:}); | |
7181 | 52 |
53 if (nargs == 0) | |
54 n = 20; | |
7182 | 55 r = [1, 1]; |
7181 | 56 elseif (nargs == 1) |
57 n = 20; | |
58 r = args{1}; | |
59 elseif (nargs == 2) | |
60 r = args{1}; | |
61 n = args{2}; | |
62 else | |
7182 | 63 print_usage (); |
7181 | 64 endif |
65 | |
7182 | 66 if (length (r) < 2) |
67 error ("cylinder: length(r) must be larger than 2") | |
7181 | 68 endif |
69 | |
7182 | 70 phi = linspace (0, 2*pi, n+1); |
7181 | 71 idx = 1:length(r); |
72 [phi, idx] = meshgrid(phi, idx); | |
73 z = (idx - 1) / (length(r) - 1); | |
74 r = r(idx); | |
7182 | 75 [x, y] = pol2cart (phi, r); |
7181 | 76 |
77 if (nargout > 0) | |
78 xx = x; | |
79 yy = y; | |
80 zz = z; | |
81 else | |
7215 | 82 surf (ax, x, y, z); |
7181 | 83 endif |
84 | |
85 endfunction | |
7245 | 86 |
87 %!demo | |
88 %! disp ("plotting a cone") | |
89 %! [x, y, z] = cylinder (10:-1:0,50); | |
90 %! surf (x, y, z); |