Mercurial > octave
annotate scripts/plot/draw/comet3.m @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
1 ## Copyright (C) 2010-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
5 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
6 ## |
11382 | 7 ## This file is part of Octave. |
8 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
9 ## Octave is free software: you can redistribute it and/or modify it |
11382 | 10 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
11 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
12 ## (at your option) any later version. |
11382 | 13 ## |
14 ## Octave is distributed in the hope that it will be useful, but | |
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## GNU General Public License for more details. |
11382 | 18 ## |
19 ## You should have received a copy of the GNU General Public License | |
20 ## along with Octave; see the file COPYING. If not, see | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
21 ## <https://www.gnu.org/licenses/>. |
11382 | 22 |
23 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20173
diff
changeset
|
24 ## @deftypefn {} {} comet3 (@var{z}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20173
diff
changeset
|
25 ## @deftypefnx {} {} comet3 (@var{x}, @var{y}, @var{z}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20173
diff
changeset
|
26 ## @deftypefnx {} {} comet3 (@var{x}, @var{y}, @var{z}, @var{p}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20173
diff
changeset
|
27 ## @deftypefnx {} {} comet3 (@var{hax}, @dots{}) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
28 ## Produce a simple comet style animation along the trajectory provided by |
20173
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
29 ## the input coordinate vectors (@var{x}, @var{y}, @var{z}). |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
30 ## |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
31 ## If only @var{z} is specified then @var{x}, @var{y} default to the indices |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
32 ## of @var{z}. |
11382 | 33 ## |
34 ## The speed of the comet may be controlled by @var{p}, which represents the | |
16826
a4969508008e
doc: Periodic spellcheck of the documentation.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
35 ## time each point is displayed before moving to the next one. The default for |
26666
5c46c13b43ad
comet3.m: Use constant speed regardless of size of data input.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
36 ## @var{p} is @code{5 / numel (@var{z})}. |
11382 | 37 ## |
24431
0c6cedafc71e
doc: Use 'axes' rather than 'axis' appropriately in docstrings.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
38 ## If the first argument @var{hax} is an axes handle, then plot into this axes, |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17060
diff
changeset
|
39 ## rather than the current axes returned by @code{gca}. |
16814
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
40 ## @seealso{comet} |
11382 | 41 ## @end deftypefn |
42 | |
43 function comet3 (varargin) | |
44 | |
17060
2d17dbdf6b7d
comet.m, comet3.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
45 [hax, varargin, nargin] = __plt_get_axis_arg__ ("comet3", varargin{:}); |
11382 | 46 |
47 if (nargin == 0 || nargin == 2 || nargin > 4) | |
48 print_usage (); | |
49 elseif (nargin == 1) | |
50 z = varargin{1}; | |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
51 x = y = 1:numel (z); |
26666
5c46c13b43ad
comet3.m: Use constant speed regardless of size of data input.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
52 p = 5 / numel (z); |
11382 | 53 elseif (nargin == 3) |
54 x = varargin{1}; | |
55 y = varargin{2}; | |
56 z = varargin{3}; | |
26666
5c46c13b43ad
comet3.m: Use constant speed regardless of size of data input.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
57 p = 5 / numel (z); |
11382 | 58 elseif (nargin == 4) |
59 x = varargin{1}; | |
60 y = varargin{2}; | |
61 z = varargin{3}; | |
62 p = varargin{4}; | |
63 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
64 |
17211
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17190
diff
changeset
|
65 oldfig = []; |
17301
68bcac3c043a
Correct inversion accidentally introduced in cset 87ba70043bfc.
Rik <rik@octave.org>
parents:
17211
diff
changeset
|
66 if (! isempty (hax)) |
17211
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17190
diff
changeset
|
67 oldfig = get (0, "currentfigure"); |
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17190
diff
changeset
|
68 endif |
11382 | 69 unwind_protect |
17060
2d17dbdf6b7d
comet.m, comet3.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
70 hax = newplot (hax); |
2d17dbdf6b7d
comet.m, comet3.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
71 limits = [min(x), max(x), min(y), max(y), min(z), max(z)]; |
11382 | 72 num = numel (y); |
73 dn = round (num/10); | |
17187
1c2f14a7935d
comet3.m: Speed up animation by using low-level graphic commands.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
74 |
1c2f14a7935d
comet3.m: Speed up animation by using low-level graphic commands.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
75 hl = plot3 (x(1), y(1), z(1), "color", "r", "marker", "none", |
1c2f14a7935d
comet3.m: Speed up animation by using low-level graphic commands.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
76 x(1), y(1), z(1), "color", "g", "marker", "none", |
1c2f14a7935d
comet3.m: Speed up animation by using low-level graphic commands.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
77 x(1), y(1), z(1), "color", "b", "marker", "o"); |
1c2f14a7935d
comet3.m: Speed up animation by using low-level graphic commands.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
78 axis (limits); # set manual limits to speed up plotting |
1c2f14a7935d
comet3.m: Speed up animation by using low-level graphic commands.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
79 |
26666
5c46c13b43ad
comet3.m: Use constant speed regardless of size of data input.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
80 ## Initialize the timer |
5c46c13b43ad
comet3.m: Use constant speed regardless of size of data input.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
81 t = p; |
5c46c13b43ad
comet3.m: Use constant speed regardless of size of data input.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
82 timerid = tic (); |
5c46c13b43ad
comet3.m: Use constant speed regardless of size of data input.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
83 |
26268
6dd232798997
maint: Remove useless ';' from end of for, if, while, etc. statements.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
84 for n = 2:(num+dn) |
11382 | 85 m = n - dn; |
86 m = max ([m, 1]); | |
87 k = min ([n, num]); | |
17187
1c2f14a7935d
comet3.m: Speed up animation by using low-level graphic commands.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
88 set (hl(1), "xdata", x(1:m), "ydata", y(1:m), "zdata", z(1:m)); |
1c2f14a7935d
comet3.m: Speed up animation by using low-level graphic commands.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
89 set (hl(2), "xdata", x(m:k), "ydata", y(m:k), "zdata", z(m:k)); |
1c2f14a7935d
comet3.m: Speed up animation by using low-level graphic commands.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
90 set (hl(3), "xdata", x(k) , "ydata", y(k) , "zdata", z(k)); |
26666
5c46c13b43ad
comet3.m: Use constant speed regardless of size of data input.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
91 |
5c46c13b43ad
comet3.m: Use constant speed regardless of size of data input.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
92 pause (t - toc (timerid)); |
5c46c13b43ad
comet3.m: Use constant speed regardless of size of data input.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
93 t += p; |
11382 | 94 endfor |
95 unwind_protect_cleanup | |
17060
2d17dbdf6b7d
comet.m, comet3.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
96 if (! isempty (oldfig)) |
2d17dbdf6b7d
comet.m, comet3.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
97 set (0, "currentfigure", oldfig); |
2d17dbdf6b7d
comet.m, comet3.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16826
diff
changeset
|
98 endif |
11382 | 99 end_unwind_protect |
100 | |
101 endfunction | |
102 | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
103 |
11382 | 104 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
105 %! clf; |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
106 %! title ("comet3() animation"); |
17190
df4c4b7708a4
Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents:
17187
diff
changeset
|
107 %! view (3); hold on; |
11382 | 108 %! t = 0:pi/20:5*pi; |
26666
5c46c13b43ad
comet3.m: Use constant speed regardless of size of data input.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
109 %! comet3 (cos (t), sin (t), t); |
17190
df4c4b7708a4
Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents:
17187
diff
changeset
|
110 %! hold off; |