changelog shortlog tags changeset files revisions annotate raw

scripts/plot/cylinder.m

changeset 10289: 4b124317dc38
parent:1bf0ce0930be
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (62 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1## Copyright (C) 2007, 2009 Michael Goffioul and 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
33## @code{surf (@var{x}, @var{y}, @var{z})}. If an axes handle @var{ax}
34## is passed as the first argument, the surface is plotted to this set
35## of axes.
36##
37## Examples:
38## @example
39## @group
40## disp ("plotting a cone")
41## [x, y, z] = cylinder (10:-1:0,50);
42## surf (x, y, z);
43## @end group
44## @end example
45## @seealso{sphere}
46## @end deftypefn
47
48function [xx, yy, zz] = cylinder (varargin)
49
50 [ax, args, nargs] = __plt_get_axis_arg__ ((nargout > 0), "cylinder",
51 varargin{:});
52
53 if (nargs == 0)
54 n = 20;
55 r = [1, 1];
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
63 print_usage ();
64 endif
65
66 if (length (r) < 2)
67 error ("cylinder: length(r) must be larger than 2")
68 endif
69
70 phi = linspace (0, 2*pi, n+1);
71 idx = 1:length(r);
72 [phi, idx] = meshgrid(phi, idx);
73 z = (idx - 1) / (length(r) - 1);
74 r = r(idx);
75 [x, y] = pol2cart (phi, r);
76
77 if (nargout > 0)
78 xx = x;
79 yy = y;
80 zz = z;
81 else
82 surf (ax, x, y, z);
83 endif
84
85endfunction
86
87%!demo
88%! disp ("plotting a cone")
89%! [x, y, z] = cylinder (10:-1:0,50);
90%! surf (x, y, z);