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 |
3402
|
20 ## usage: function __plr2__ (theta, rho, fmt) |
|
21 |
2314
|
22 ## Author: jwe |
|
23 |
2315
|
24 function __plr2__ (theta, rho, fmt) |
933
|
25 |
|
26 if (nargin != 3) |
2315
|
27 usage ("__plr2__ (theta, rho, fmt)"); |
933
|
28 endif |
|
29 |
|
30 if (any (imag (theta))) |
|
31 theta = real (theta); |
|
32 endif |
|
33 |
|
34 if (any (imag (rho))) |
|
35 rho = real (rho); |
|
36 endif |
|
37 |
|
38 if (is_scalar (theta)) |
|
39 if (is_scalar (rho)) |
|
40 x = rho * cos (theta); |
|
41 y = rho * sin (theta); |
2315
|
42 __plt2ss__ (x, y, fmt); |
933
|
43 endif |
|
44 elseif (is_vector (theta)) |
|
45 if (is_vector (rho)) |
|
46 if (length (theta) != length (rho)) |
3426
|
47 error ("polar: vector lengths must match"); |
933
|
48 endif |
|
49 if (rows (rho) == 1) |
3426
|
50 rho = rho'; |
933
|
51 endif |
|
52 if (rows (theta) == 1) |
3426
|
53 theta = theta'; |
933
|
54 endif |
|
55 x = rho .* cos (theta); |
|
56 y = rho .* sin (theta); |
2315
|
57 __plt2vv__ (x, y, fmt); |
933
|
58 elseif (is_matrix (rho)) |
|
59 [t_nr, t_nc] = size (theta); |
|
60 if (t_nr == 1) |
3426
|
61 theta = theta'; |
|
62 tmp = t_nr; |
|
63 t_nr = t_nc; |
|
64 t_nc = tmp; |
933
|
65 endif |
|
66 [r_nr, r_nc] = size (rho); |
|
67 if (t_nr != r_nr) |
3426
|
68 rho = rho'; |
|
69 tmp = r_nr; |
|
70 r_nr = r_nc; |
|
71 r_nc = tmp; |
933
|
72 endif |
|
73 if (t_nr != r_nr) |
3426
|
74 error ("polar: vector and matrix sizes must match"); |
933
|
75 endif |
|
76 x = diag (cos (theta)) * rho; |
|
77 y = diag (sin (theta)) * rho; |
2315
|
78 __plt2vm__ (x, y, fmt); |
933
|
79 endif |
|
80 elseif (is_matrix (theta)) |
|
81 if (is_vector (rho)) |
|
82 [r_nr, r_nc] = size (rho); |
|
83 if (r_nr == 1) |
3426
|
84 rho = rho'; |
|
85 tmp = r_nr; |
|
86 r_nr = r_nc; |
|
87 r_nc = tmp; |
933
|
88 endif |
|
89 [t_nr, t_nc] = size (theta); |
|
90 if (r_nr != t_nr) |
3426
|
91 theta = theta'; |
|
92 tmp = t_nr; |
|
93 t_nr = t_nc; |
|
94 t_nc = tmp; |
933
|
95 endif |
|
96 if (r_nr != t_nr) |
3426
|
97 error ("polar: vector and matrix sizes must match"); |
933
|
98 endif |
3238
|
99 diag_r = diag (rho); |
933
|
100 x = diag_r * cos (theta); |
|
101 y = diag_r * sin (theta); |
2315
|
102 __plt2mv__ (x, y, fmt); |
933
|
103 elseif (is_matrix (rho)) |
|
104 if (size (rho) != size (theta)) |
3426
|
105 error ("polar: matrix dimensions must match"); |
933
|
106 endif |
|
107 x = rho .* cos (theta); |
|
108 y = rho .* sin (theta); |
2315
|
109 __plt2mm__ (x, y, fmt); |
933
|
110 endif |
|
111 endif |
|
112 |
|
113 endfunction |