Mercurial > hg > octave-lyh
annotate scripts/plot/cylinder.m @ 9050:e15f4197d907
__go_draw_axes__.m: Properly position the title for 3D plots when using the gnuplot (v4.3+) backend.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Fri, 27 Mar 2009 18:10:38 -0400 |
parents | dbd0c77e575e |
children | 1bf0ce0930be |
rev | line source |
---|---|
7181 | 1 ## Copyright (C) 2007 Michael Goffioul, Kai Habel |
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 | |
7182 | 39 ## disp ("plotting a cone") |
40 ## [x, y, z] = cylinder (10:-1:0,50); | |
41 ## surf (x, y, z); | |
7181 | 42 ## @end example |
43 ## @seealso{sphere} | |
44 ## @end deftypefn | |
45 | |
7182 | 46 function [xx, yy, zz] = cylinder (varargin) |
7181 | 47 |
7215 | 48 [ax, args, nargs] = __plt_get_axis_arg__ ((nargout > 0), "cylinder", |
49 varargin{:}); | |
7181 | 50 |
51 if (nargs == 0) | |
52 n = 20; | |
7182 | 53 r = [1, 1]; |
7181 | 54 elseif (nargs == 1) |
55 n = 20; | |
56 r = args{1}; | |
57 elseif (nargs == 2) | |
58 r = args{1}; | |
59 n = args{2}; | |
60 else | |
7182 | 61 print_usage (); |
7181 | 62 endif |
63 | |
7182 | 64 if (length (r) < 2) |
65 error ("cylinder: length(r) must be larger than 2") | |
7181 | 66 endif |
67 | |
7182 | 68 phi = linspace (0, 2*pi, n+1); |
7181 | 69 idx = 1:length(r); |
70 [phi, idx] = meshgrid(phi, idx); | |
71 z = (idx - 1) / (length(r) - 1); | |
72 r = r(idx); | |
7182 | 73 [x, y] = pol2cart (phi, r); |
7181 | 74 |
75 if (nargout > 0) | |
76 xx = x; | |
77 yy = y; | |
78 zz = z; | |
79 else | |
7215 | 80 surf (ax, x, y, z); |
7181 | 81 endif |
82 | |
83 endfunction | |
7245 | 84 |
85 %!demo | |
86 %! disp ("plotting a cone") | |
87 %! [x, y, z] = cylinder (10:-1:0,50); | |
88 %! surf (x, y, z); |