2313
|
1 ## Copyright (C) 1996 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 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. |
245
|
19 |
934
|
20 function polar_int (theta, rho, fmt) |
4
|
21 |
|
22 if (nargin == 1) |
|
23 [nr, nc] = size (theta); |
|
24 if (nr == 1) |
1518
|
25 theta = theta.'; |
4
|
26 tmp = nr; |
|
27 nr = nc; |
|
28 nc = tmp; |
|
29 endif |
|
30 theta_i = imag (theta); |
934
|
31 if (any (theta_i)) |
4
|
32 rho = theta_i; |
|
33 theta = real (theta); |
|
34 else |
|
35 rho = theta; |
|
36 theta = (1:nr)'; |
|
37 endif |
|
38 endif |
|
39 |
|
40 if (nargin <= 2) |
934
|
41 if (any (imag (theta))) |
4
|
42 theta = real (theta); |
|
43 endif |
934
|
44 if (any (imag (rho))) |
4
|
45 rho = real (rho); |
|
46 endif |
|
47 if (is_scalar (theta)) |
|
48 if (is_scalar (rho)) |
|
49 x = rho * cos (theta); |
|
50 y = rho * sin (theta); |
934
|
51 plot_2_s_s (x, y, fmt); |
4
|
52 endif |
|
53 elseif (is_vector (theta)) |
|
54 if (is_vector (rho)) |
|
55 if (length (theta) != length (rho)) |
904
|
56 error ("polar: vector lengths must match"); |
4
|
57 endif |
|
58 if (rows (rho) == 1) |
1518
|
59 rho = rho.'; |
4
|
60 endif |
|
61 if (rows (theta) == 1) |
1518
|
62 theta = theta.'; |
4
|
63 endif |
|
64 x = rho .* cos (theta); |
|
65 y = rho .* sin (theta); |
934
|
66 plot_2_v_v (x, y, fmt); |
4
|
67 elseif (is_matrix (rho)) |
|
68 [t_nr, t_nc] = size (theta); |
|
69 if (t_nr == 1) |
1518
|
70 theta = theta.'; |
4
|
71 tmp = t_nr; |
|
72 t_nr = t_nc; |
|
73 t_nc = tmp; |
|
74 endif |
|
75 [r_nr, r_nc] = size (rho); |
|
76 if (t_nr != r_nr) |
1518
|
77 rho = rho.'; |
4
|
78 tmp = r_nr; |
|
79 r_nr = r_nc; |
|
80 r_nc = tmp; |
|
81 endif |
|
82 if (t_nr != r_nr) |
904
|
83 error ("polar: vector and matrix sizes must match"); |
4
|
84 endif |
|
85 x = diag (cos (theta)) * rho; |
|
86 y = diag (sin (theta)) * rho; |
934
|
87 plot_2_v_m (x, y, fmt); |
4
|
88 endif |
|
89 elseif (is_matrix (theta)) |
|
90 if (is_vector (rho)) |
|
91 [r_nr, r_nc] = size (rho); |
|
92 if (r_nr == 1) |
1518
|
93 rho = rho.'; |
4
|
94 tmp = r_nr; |
|
95 r_nr = r_nc; |
|
96 r_nc = tmp; |
|
97 endif |
|
98 [t_nr, t_nc] = size (theta); |
|
99 if (r_nr != t_nr) |
1518
|
100 theta = rho.'; |
4
|
101 tmp = t_nr; |
|
102 t_nr = t_nc; |
|
103 t_nc = tmp; |
|
104 endif |
|
105 if (r_nr != t_nr) |
904
|
106 error ("polar: vector and matrix sizes must match"); |
4
|
107 endif |
|
108 diag_r = diag (r); |
|
109 x = diag_r * cos (theta); |
|
110 y = diag_r * sin (theta); |
934
|
111 plot_2_m_v (x, y, fmt); |
4
|
112 elseif (is_matrix (rho)) |
|
113 if (size (rho) != size (theta)) |
904
|
114 error ("polar: matrix dimensions must match"); |
4
|
115 endif |
|
116 x = rho .* cos (theta); |
|
117 y = rho .* sin (theta); |
934
|
118 plot_2_m_m (x, y, fmt); |
4
|
119 endif |
|
120 endif |
|
121 else |
904
|
122 usage ("polar_int (x [, y])"); |
4
|
123 endif |
|
124 |
|
125 endfunction |