Mercurial > hg > octave-nkf
annotate scripts/plot/util/rotate.m @ 19344:0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
* doc/interpreter/contrib.txi, doc/interpreter/expr.txi,
doc/interpreter/func.txi, doc/interpreter/linalg.txi, doc/interpreter/plot.txi,
libinterp/corefcn/data.cc, libinterp/corefcn/debug.cc,
libinterp/corefcn/graphics.cc, libinterp/corefcn/help.cc,
libinterp/corefcn/load-save.cc, libinterp/corefcn/profiler.cc,
libinterp/corefcn/syscalls.cc, libinterp/corefcn/utils.cc,
libinterp/corefcn/variables.cc, libinterp/dldfcn/__init_fltk__.cc,
scripts/general/deal.m, scripts/help/__gripe_missing_component__.m,
scripts/miscellaneous/desktop.m, scripts/pkg/private/default_prefix.m,
scripts/plot/appearance/__getlegenddata__.m, scripts/plot/util/pan.m,
scripts/plot/util/rotate.m, scripts/plot/util/rotate3d.m,
scripts/plot/util/zoom.m, scripts/signal/periodogram.m,
scripts/specfun/factor.m, scripts/specfun/primes.m,
scripts/statistics/base/lscov.m, scripts/testfun/private/compare_plot_demos.m,
scripts/testfun/private/dump_demos.m,
scripts/testfun/private/html_compare_plot_demos.m, scripts/testfun/test.m:
Periodic grammarcheck of documentation.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 22 Sep 2014 20:46:54 -0700 |
parents | 89ba3b13e6a5 |
children | 26d1c3b73174 |
rev | line source |
---|---|
19273 | 1 ## Copyright (C) 2014 John W. Eaton |
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 -*- | |
19344
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19275
diff
changeset
|
20 ## @deftypefn {Function File} {} rotate (@var{h}, @var{dir}, @var{alpha}) |
19273 | 21 ## @deftypefnx {Function File} {} rotate (@dots{}, @var{origin}) |
22 ## Rotate the plot object @var{h} through @var{alpha} degrees around | |
23 ## the line with direction @var{dir} and origin @var{origin}. | |
24 ## | |
25 ## The default value of @var{origin} is the center of the axes | |
26 ## object that is the parent of @var{h}. | |
27 ## | |
28 ## If @var{h} is a vector of handles, they must all have the same | |
29 ## parent axes object. | |
30 ## | |
31 ## Graphics objects that may be rotated are lines, surfaces, patches, | |
32 ## and images. | |
33 ## @end deftypefn | |
34 | |
35 function rotate (h, direction, alpha, origin) | |
36 | |
37 ## Note in doc string about compatibility issues with calculation of | |
38 ## default origin due to possible differences in the auto-scaling | |
39 ## algorithm between Octave and Matlab. | |
40 | |
41 if (nargin < 3 || nargin > 4) | |
42 print_unage (); | |
43 endif | |
44 | |
45 is_h = ishandle (h); | |
46 if (is_h) | |
47 ax_list = get (h, "parent"); | |
48 if (iscell (ax_list)) | |
49 ax_list = cell2mat (ax_list); | |
50 endif | |
51 if (ax_list == ax_list(1)) | |
52 ax = ax_list(1); | |
53 else | |
54 error ("rotate: all handles must be children of the same axes object"); | |
55 endif | |
56 else | |
57 error ("rotate: H must be an array of one or more graphics handles"); | |
58 endif | |
59 | |
60 if (! (isnumeric (direction) && numel (direction) == 3)) | |
61 error ("rotate: invalid direction"); | |
62 endif | |
63 | |
64 if (! (isnumeric (alpha) && isscalar (alpha))) | |
65 error ("rotate: invalid rotation angle"); | |
66 endif | |
67 | |
68 t = get (h, "type"); | |
69 | |
70 is_image = strcmp (t, "image"); | |
71 is_line = strcmp (t, "line"); | |
72 is_patch = strcmp (t, "patch"); | |
73 is_surface = strcmp (t, "surface"); | |
74 | |
75 if (! all (is_image | is_line | is_patch | is_surface)) | |
76 error ("rotate: expecting image, line, patch, or surface objects"); | |
77 endif | |
78 | |
79 if (nargin == 4) | |
80 if (! (isnumeric (origin) && numel (origin) == 3)) | |
81 error ("rotate: invalid origin"); | |
82 endif | |
83 else | |
84 ## Should Z limit be considered when computing origin? | |
85 | |
86 use_zlim = any (is_patch | is_surface); | |
87 | |
88 if (! use_zlim && any (is_line)) | |
89 idx = find (is_line)'; | |
90 for i = idx | |
91 if (! isempty (get (h(i), "zdata"))) | |
92 use_zlim = true; | |
93 break; | |
94 endif | |
95 endfor | |
96 endif | |
97 | |
98 xlim = get (ax, "xlim"); | |
99 ylim = get (ax, "ylim"); | |
100 | |
101 a = (xlim(1) + xlim(2)) / 2; | |
102 b = (ylim(1) + ylim(2)) / 2; | |
103 | |
104 if (use_zlim) | |
105 zlim = get (ax, "zlim"); | |
106 c = (zlim(1) + zlim(2)) / 2; | |
107 else | |
108 c = 0; | |
109 endif | |
110 | |
111 origin = [a, b, c]; | |
112 endif | |
113 | |
114 direction = direction / norm (direction); | |
115 | |
116 u = direction(1); | |
117 v = direction(2); | |
118 w = direction(3); | |
119 | |
120 a = origin(1); | |
121 b = origin(2); | |
122 c = origin(3); | |
123 | |
124 sa = sind (alpha); | |
125 ca = cosd (alpha); | |
126 | |
127 for i = 1:numel (h) | |
128 x = get (h(i), "xdata"); | |
129 y = get (h(i), "ydata"); | |
130 | |
131 if (is_image(i)) | |
132 z = zeros (size (x)); | |
133 else | |
134 z = get (h(i), "zdata"); | |
135 if (isempty (z)) | |
136 z = zeros (size (x)); | |
137 elseif (isvector (x) && isvector (y) && ! isvector (z)) | |
138 [x, y] = meshgrid (x, y); | |
139 endif | |
140 endif | |
141 | |
142 if (a == 0 && b == 0 && c == 0) | |
143 tmp = (u*x + v*y + w*z) * (1 - ca); | |
144 | |
145 xr = u*tmp + x*ca + (-w*y + v*z)*sa; | |
146 yr = v*tmp + y*ca + (w*x - u*z)*sa; | |
147 zr = w*tmp + z*ca + (-v*x + u*y)*sa; | |
148 else | |
149 one_m_ca = 1 - ca; | |
150 tmp = u*x + v*y + w*z; | |
151 | |
152 xr = ((a*(v**2 + w**2) - u*(b*v + c*w - tmp))*one_m_ca | |
153 + x*ca + (-c*v + b*w - w*y + v*z)*sa); | |
154 yr = ((b*(u**2 + w**2) - v*(a*u + c*w - tmp))*one_m_ca | |
155 + y*ca + (c*u - a*w + w*x - u*z)*sa); | |
156 zr = ((c*(u**2 + v**2) - w*(a*u + b*v - tmp))*one_m_ca | |
157 + z*ca + (-b*u + a*v - v*x + u*y)*sa); | |
158 endif | |
159 | |
160 set (h(i), "xdata", xr, "ydata", yr); | |
161 | |
162 if (! is_image(i)) | |
163 set (h(i), "zdata", zr); | |
164 endif | |
165 endfor | |
166 | |
167 endfunction | |
168 | |
169 %% Test input validation | |
170 %!shared h1, h2, o1, o2, o3 | |
171 %! h1 = figure ("visible", "off"); | |
172 %! o1 = line (); | |
173 %! h2 = figure ("visible", "off"); | |
174 %! o2 = line (); | |
175 %! o3 = text (0, 0, "foobar"); | |
176 %!error rotate () | |
177 %!error rotate (o1) | |
178 %!error rotate (o1, [0,0,0]); | |
179 %!error <all handles must be children of the same axes object> rotate ([o1, o2], [0,0,0], 90); | |
180 %!error <invalid direction> rotate (o1, "foo", 90); | |
181 %!error <invalid rotation angle> rotate (o1, [0,0,0], "foo"); | |
182 %!error <invalid origin> rotate (o1, [0,0,0], 90, "foo"); | |
183 %!error rotate (o1, [0,0,0], 90, [0,0,0], 1); | |
184 %!error <H must be an array of one or more graphics handles> rotate (NaN, [0,0,0], 90); | |
185 %!error <expecting image, line, patch, or surface objects> rotate (o3, [0,0,0], 90); | |
186 %!test | |
187 %! close (h1); | |
188 %! close (h2); |