2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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 2, or (at your option) |
|
8 ## 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, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
933
|
19 |
3449
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} __plr2__ (@var{theta}, @var{rho}, @var{fmt}) |
|
22 ## @end deftypefn |
3402
|
23 |
2314
|
24 ## Author: jwe |
|
25 |
2315
|
26 function __plr2__ (theta, rho, fmt) |
933
|
27 |
|
28 if (nargin != 3) |
2315
|
29 usage ("__plr2__ (theta, rho, fmt)"); |
933
|
30 endif |
|
31 |
|
32 if (any (imag (theta))) |
|
33 theta = real (theta); |
|
34 endif |
|
35 |
|
36 if (any (imag (rho))) |
|
37 rho = real (rho); |
|
38 endif |
|
39 |
4030
|
40 if (isscalar (theta)) |
|
41 if (isscalar (rho)) |
933
|
42 x = rho * cos (theta); |
|
43 y = rho * sin (theta); |
2315
|
44 __plt2ss__ (x, y, fmt); |
933
|
45 endif |
4030
|
46 elseif (isvector (theta)) |
|
47 if (isvector (rho)) |
933
|
48 if (length (theta) != length (rho)) |
3426
|
49 error ("polar: vector lengths must match"); |
933
|
50 endif |
|
51 if (rows (rho) == 1) |
3426
|
52 rho = rho'; |
933
|
53 endif |
|
54 if (rows (theta) == 1) |
3426
|
55 theta = theta'; |
933
|
56 endif |
|
57 x = rho .* cos (theta); |
|
58 y = rho .* sin (theta); |
2315
|
59 __plt2vv__ (x, y, fmt); |
4030
|
60 elseif (ismatrix (rho)) |
933
|
61 [t_nr, t_nc] = size (theta); |
|
62 if (t_nr == 1) |
3426
|
63 theta = theta'; |
|
64 tmp = t_nr; |
|
65 t_nr = t_nc; |
|
66 t_nc = tmp; |
933
|
67 endif |
|
68 [r_nr, r_nc] = size (rho); |
|
69 if (t_nr != r_nr) |
3426
|
70 rho = rho'; |
|
71 tmp = r_nr; |
|
72 r_nr = r_nc; |
|
73 r_nc = tmp; |
933
|
74 endif |
|
75 if (t_nr != r_nr) |
3426
|
76 error ("polar: vector and matrix sizes must match"); |
933
|
77 endif |
|
78 x = diag (cos (theta)) * rho; |
|
79 y = diag (sin (theta)) * rho; |
2315
|
80 __plt2vm__ (x, y, fmt); |
933
|
81 endif |
4030
|
82 elseif (ismatrix (theta)) |
|
83 if (isvector (rho)) |
933
|
84 [r_nr, r_nc] = size (rho); |
|
85 if (r_nr == 1) |
3426
|
86 rho = rho'; |
|
87 tmp = r_nr; |
|
88 r_nr = r_nc; |
|
89 r_nc = tmp; |
933
|
90 endif |
|
91 [t_nr, t_nc] = size (theta); |
|
92 if (r_nr != t_nr) |
3426
|
93 theta = theta'; |
|
94 tmp = t_nr; |
|
95 t_nr = t_nc; |
|
96 t_nc = tmp; |
933
|
97 endif |
|
98 if (r_nr != t_nr) |
3426
|
99 error ("polar: vector and matrix sizes must match"); |
933
|
100 endif |
3238
|
101 diag_r = diag (rho); |
933
|
102 x = diag_r * cos (theta); |
|
103 y = diag_r * sin (theta); |
2315
|
104 __plt2mv__ (x, y, fmt); |
4030
|
105 elseif (ismatrix (rho)) |
933
|
106 if (size (rho) != size (theta)) |
3426
|
107 error ("polar: matrix dimensions must match"); |
933
|
108 endif |
|
109 x = rho .* cos (theta); |
|
110 y = rho .* sin (theta); |
2315
|
111 __plt2mm__ (x, y, fmt); |
933
|
112 endif |
|
113 endif |
|
114 |
|
115 endfunction |