File: polar.m

package info (click to toggle)
octave 11.0.92-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 148,624 kB
  • sloc: cpp: 347,499; ansic: 85,112; fortran: 20,693; objc: 10,276; sh: 8,747; lex: 4,496; yacc: 4,406; perl: 1,544; java: 1,365; awk: 1,282; makefile: 666; xml: 192
file content (706 lines) | stat: -rw-r--r-- 22,633 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
########################################################################
##
## Copyright (C) 1993-2026 The Octave Project Developers
##
## See the file COPYRIGHT.md in the top-level directory of this
## distribution or <https://octave.org/copyright/>.
##
## This file is part of Octave.
##
## Octave is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING.  If not, see
## <https://www.gnu.org/licenses/>.
##
########################################################################

## -*- texinfo -*-
## @deftypefn  {} {} polar (@var{theta}, @var{rho})
## @deftypefnx {} {} polar (@var{theta}, @var{rho}, @var{fmt})
## @deftypefnx {} {} polar (@var{cplx})
## @deftypefnx {} {} polar (@var{cplx}, @var{fmt})
## @deftypefnx {} {} polar (@var{hax}, @dots{})
## @deftypefnx {} {@var{h} =} polar (@dots{})
## Create a 2-D plot from polar coordinates @var{theta} and @var{rho}.
##
## The input @var{theta} is assumed to be radians and is converted to degrees
## for plotting.  If you have degrees then you must convert
## (@pxref{XREFcart2pol,,@code{cart2pol}}) to radians before passing the
## data to this function.
##
## If a single complex input @var{cplx} is given then the real part is used
## for @var{theta} and the imaginary part is used for @var{rho}.
##
## The optional argument @var{fmt} specifies the line format in the same way
## as @code{plot}.
##
## If the first argument @var{hax} is an axes handle, then plot into this axes,
## rather than the current axes returned by @code{gca}.
##
## The optional return value @var{h} is a graphics handle to the created plot.
##
## Implementation Note: The polar axis is drawn using line and text objects
## encapsulated in an hggroup.  The hggroup properties are linked to the
## original axes object such that altering an appearance property, for example
## @code{fontname}, will update the polar axis.  Two new properties are
## added to the original axes--@code{rtick}, @code{ttick}--which replace
## @code{xtick}, @code{ytick}.  The first is a list of tick locations in the
## radial (rho) direction; The second is a list of tick locations in the
## angular (theta) direction specified in degrees, i.e., in the range 0--359.
## @seealso{rose, compass, plot, cart2pol}
## @end deftypefn

function h = polar (varargin)

  [hax, varargin, nargs] = __plt_get_axis_arg__ ("polar", varargin{:});

  if (nargs < 1)
    print_usage ();
  endif

  hax = newplot (hax);

  if (nargs == 3)
    if (! ischar (varargin{3}))
      error ("polar: FMT argument must be a string");
    endif
    htmp = __plr2__ (hax, varargin{:});
    maxr = max (abs (varargin{2}(:)));
  elseif (nargs == 2)
    if (ischar (varargin{2}))
      htmp = __plr1__ (hax, varargin{:});
      if (iscomplex (varargin{1}))
        maxr = max (abs (imag (varargin{1})(:)));
      else
        maxr = max (abs (varargin{1}(:)));
      endif
    else
      fmt = "";
      htmp = __plr2__ (hax, varargin{:}, fmt);
      maxr = max (abs (varargin{2}(:)));
    endif
  elseif (nargs == 1)
    fmt = "";
    htmp = __plr1__ (hax, varargin{:}, fmt);
    if (iscomplex (varargin{1}))
      maxr = max (abs (imag (varargin{1})(:)));
    else
      maxr = max (abs (varargin{1}(:)));
    endif
  else
    print_usage ();
  endif

  if (! ishold (hax))
    hg = hggroup (hax, "tag", "polar_grid", "handlevisibility", "off");

    set (hax, "visible", "off", "plotboxaspectratio", [1, 1, 1],
              "zlim", [-1 1], "tag", "polaraxes");

    if (! isprop (hax, "rtick"))
      addproperty ("rtick", hax, "data");
    endif

    set (hax, "rtick", __calc_rtick__ (hax, maxr));

    ## add t(heta)tick
    if (! isprop (hax, "ttick"))
      addproperty ("ttick", hax, "data");
    endif

    ## theta(angular) ticks in degrees
    set (hax, "ttick", 0:30:330);

    __update_polar_grid__ (hax, [], hg);

    set (hg, "deletefcn", {@resetaxis, hax});

    addlistener (hax, "rtick", {@__update_polar_grid__, hg});
    addlistener (hax, "ttick", {@__update_polar_grid__, hg});
    addlistener (hax, "color", {@__update_patch__, hg});
    addlistener (hax, "fontangle", {@__update_text__, hg, "fontangle"});
    addlistener (hax, "fontname", {@__update_text__, hg, "fontname"});
    addlistener (hax, "fontsize", {@__update_text__, hg, "fontsize"});
    addlistener (hax, "fontunits", {@__update_text__, hg, "fontunits"});
    addlistener (hax, "fontweight", {@__update_text__, hg, "fontweight"});
    addlistener (hax, "ticklabelinterpreter",
                 {@__update_text__, hg, "interpreter", ...
                  "ticklabelinterpreter"});
    addlistener (hax, "layer", {@__update_layer__, hg});
    addlistener (hax, "gridlinestyle",{@__update_lines__,hg,"gridlinestyle"});
    addlistener (hax, "linewidth", {@__update_lines__, hg, "linewidth"});
  else
    hg = findall (hax, "tag", "polar_grid");
    if (! isempty (hg))
      oldrtick = max (get (hax, "rtick"));
      if (maxr > oldrtick)
        set (hax, "rtick", __calc_rtick__ (hax, maxr));
      endif
    endif
  endif

  if (nargout > 0)
    h = htmp;
  endif

endfunction

function rtick = __calc_rtick__ (hax, maxr)

  ## FIXME: workaround: calculate r(ho)tick from xtick
  ##        It would be better to just calculate the values,
  ##        but that code is deep in the C++ for the plot engines.
  saved_lims = get (hax, {"xlim", "ylim"});
  set (hax, "xlim", [-maxr maxr], "ylim", [-maxr maxr]);

  xtick = get (hax, "xtick");
  minidx = find (xtick >= 0, 1);
  maxidx = find (xtick >= maxr, 1);
  if (! isempty (maxidx))
    rtick = xtick(minidx:maxidx);
  else
    ## Add one more tick through linear interpolation
    rtick = xtick(minidx:end);
    rtick(end+1) = xtick(end) + diff (xtick(end-1:end));
  endif

  set (hax, {"xlim", "ylim"}, saved_lims);

endfunction

function retval = __plr1__ (h, theta, fmt)

  theta = theta(:);
  if (iscomplex (theta))
    rho = imag (theta);
    theta = real (theta);
  else
    rho = theta;
    theta = (1:rows (rho))';
  endif

  retval = __plr2__ (h, theta, rho, fmt);

endfunction

function retval = __plr2__ (h, theta, rho, fmt)

  if (ndims (theta) > 2 || ndims (rho) > 2)
    error ("polar: THETA and RHO must be 2-D objects");
  endif

  theta = real (theta);
  rho = real (rho);

  if (isscalar (theta))
    if (isscalar (rho))
      x = rho * cos (theta);
      y = rho * sin (theta);
      retval = __plt__ ("polar", h, x, y, fmt);
    else
      error ("polar: Can't plot constant THETA with varying RHO");
    endif
  elseif (isvector (theta))
    if (isvector (rho))
      if (length (theta) != length (rho))
        error ("polar: THETA and RHO vector lengths must match");
      endif
      rho = rho(:);
      theta = theta(:);
      x = rho .* cos (theta);
      y = rho .* sin (theta);
      retval = __plt__ ("polar", h, x, y, fmt);
    elseif (ismatrix (rho))
      theta = theta(:);
      t_nr = rows (theta);
      [r_nr, r_nc] = size (rho);
      if (t_nr != r_nr)
        rho = rho';
        r_nr = r_nc;
      endif
      if (t_nr != r_nr)
        error ("polar: THETA vector and RHO matrix sizes must match");
      endif
      x = diag (cos (theta)) * rho;
      y = diag (sin (theta)) * rho;
      retval = __plt__ ("polar", h, x, y, fmt);
    else
      error ("polar: invalid data for plotting");
    endif
  elseif (ismatrix (theta))
    if (isvector (rho))
      rho = rho(:);
      r_nr = rows (rho);
      [t_nr, t_nc] = size (theta);
      if (r_nr != t_nr)
        theta = theta';
        t_nr = t_nc;
      endif
      if (r_nr != t_nr)
        error ("polar: THETA matrix and RHO vector sizes must match");
      endif
      diag_r = diag (rho);
      x = diag_r * cos (theta);
      y = diag_r * sin (theta);
      retval = __plt__ ("polar", h, x, y, fmt);
    elseif (ismatrix (rho))
      if (! size_equal (rho, theta))
        error ("polar: THETA and RHO matrix dimensions must match");
      endif
      x = rho .* cos (theta);
      y = rho .* sin (theta);
      retval = __plt__ ("polar", h, x, y, fmt);
    else
      error ("polar: invalid data for plotting");
    endif
  else
    error ("polar: invalid data for plotting");
  endif

endfunction

## Callback functions for listeners

function __update_text__ (hax, ~, hg, prop, axprop = "")

  if (isempty (axprop))
    axprop = prop;
  endif

  kids = get (hg, "children");
  idx = strcmp (get (kids, "type"), "text");
  set (kids(idx).', prop, get (hax, axprop));

endfunction

function __update_lines__ (hax, ~, hg, prop)

  kids = get (hg, "children");
  idx = strcmp (get (kids, "type"), "line");
  lprop = prop;
  if (strcmp (prop, "gridlinestyle"))
    lprop = "linestyle";
  endif
  set (kids(idx).', lprop, get (hax, prop));

endfunction

function __update_patch__ (hax, ~, hg)

  kids = get (hg, "children");
  idx = strcmp (get (kids, "type"), "patch");
  set (kids(idx).', "facecolor", get (hax, "color"));

endfunction

function __update_layer__ (hax, ~, hg)

  ## FIXME: This re-implements allchild() because setting the "children"
  ##        property needs to preserve all children (titles, xlabels, etc.).
  shh = get (0, "showhiddenhandles");
  unwind_protect
    set (0, "showhiddenhandles", "on");
    kids = get (hax, "children");
    if (strcmp (get (hax, "layer"), "bottom"))
      set (hax, "children", [kids(kids != hg); hg]);
    else
      set (hax, "children", [hg; kids(kids != hg)]);
    endif
  unwind_protect_cleanup
    set (0, "showhiddenhandles", shh);
  end_unwind_protect

endfunction

function __update_polar_grid__ (hax, ~, hg)

  ## Delete existing polar grid
  delete (get (hg, "children"));

  rtick = unique (get (hax, "rtick")(:)');
  rtick = rtick(rtick > 0);
  if (isempty (rtick))
    rtick = [0.5, 1];
  endif

  ttick = unique (get (hax, "ttick")(:)');
  ttick = ttick(ttick >= 0);
  if (isempty (ttick))
    ttick = 0:30:330;
  endif

  lprops = {"linestyle", get(hax, "gridlinestyle"), ...
            "linewidth", get(hax, "linewidth"), ...
            "color", min(5.8167 * get(hax, "xcolor"), 1)};
  ## "fontunits" should be first because it affects "fontsize" property.
  tprops(1:2:12) = {"fontunits", "fontangle", "fontname", "fontsize", ...
                    "fontweight", "ticklabelinterpreter"};
  tprops(2:2:12) = get (hax, tprops(1:2:12));
  tprops(1:2:12) = strrep (tprops(1:2:12), "ticklabelinterpreter",
                           "interpreter");

  ## The number of points used for a circle
  circle_points = 50;
  t = linspace (0, 2*pi, circle_points)';
  x = kron (cos (t), rtick);
  y = kron (sin (t), rtick);

  ## Draw colored disk in the Z=0 plane for solid background and border.
  ## FIXME: Patch solid border is not visible through polar plot lines.  If
  ##        solid border visibility is needed without obscuring other plot
  ##        features additional line objects may be needed.
  patch (x(:,end), y(:,end), zeros (circle_points, 1),
         get (hax, "color"), "parent", hg);

  ## Plot grid circles
  line (x(:,1:end-1), y(:,1:end-1), lprops{:}, "parent", hg);

  ## Outer circle (axes "box") is always drawn solid
  line (x(:,end), y(:,end), lprops{:}, "linestyle", "-", "parent", hg);

  ## Add radial labels
  ## Labels are arranged along a radius with an angle of 75 degrees.
  ## 2% addition puts a small visual gap between grid circle and label.
  [x, y] = pol2cart (0.42 * pi, rtick + (.02 * max (rtick(:))));
  text (x, y, num2cell (rtick), "verticalalignment", "bottom", tprops{:},
        "parent", hg);

  ## Add radial lines
  [x, y] = pol2cart (deg2rad (ttick), rtick(end));
  x = [zeros(1, numel (ttick)); x];
  y = [zeros(1, numel (ttick)); y];
  line (x, y, "linestyle", ":", lprops{:}, "parent", hg);

  ## Add angular labels
  tticklabel = num2cell (ttick);
  ## FIXME: The 1.08 factor does not work as fontsize increases
  [x, y] = pol2cart (deg2rad (ttick), 1.08 * rtick(end));
  text (x, y, tticklabel, "horizontalalignment", "center", tprops{:},
        "parent", hg);

  lim = 1.1 * rtick(end);
  set (hax, "xlim", [-lim, lim], "ylim", [-lim, lim]);

  ## Put polar grid behind or ahead of plot
  __update_layer__ (hax, [], hg);

endfunction

function resetaxis (~, ~, hax)

  if (isaxes (hax))
    dellistener (hax, "rtick");
    dellistener (hax, "ttick");
    dellistener (hax, "color");
    dellistener (hax, "fontangle");
    dellistener (hax, "fontname");
    dellistener (hax, "fontsize");
    dellistener (hax, "fontunits");
    dellistener (hax, "fontweight");
    dellistener (hax, "ticklabelinterpreter");
    dellistener (hax, "layer");
    dellistener (hax, "gridlinestyle");
    dellistener (hax, "linewidth");
  endif

endfunction


%!demo
%! clf;
%! theta = linspace (0,2*pi,1000);
%! rho = sin (7*theta);
%! polar (theta, rho);
%! title ("polar() plot");

%!demo
%! clf;
%! theta = linspace (0,2*pi,1000);
%! cplx = theta + i*sin (7*theta);
%! polar (cplx, "g");
%! title ("polar() plot of complex data");

%!demo
%! clf;
%! theta = linspace (0,2*pi,1000);
%! rho = sin (2*theta).*cos (2*theta);
%! polar (theta, rho, "--r");
%! set (gca, "rtick", 0.1:0.1:0.6, "ttick", 0:20:340);
%! title ("polar() plot with finer grid");

%!demo
%! clf;
%! theta = linspace (0,2*pi,1000);
%! rho = sin (2*theta).*cos (2*theta);
%! polar (theta, rho, "--b");
%! set (gca, "fontsize", 12, "linewidth", 2, "color", [0.8 0.8 0.8]);
%! title ("polar() plot with modified axis appearance");

%!demo
%! clf;
%! theta = linspace (0,8*pi,1000);
%! rho = sin (5/4*theta);
%! polar (theta, rho);
%! set (gca, "rtick", 0.2:0.2:1);
%! title ("polar() plot");

%!demo
%! clf;
%! theta = linspace (0,8*pi,1000);
%! rho = sin (5/4*theta);
%! polar (theta, rho);
%! view (90, -90);
%! title ("polar() plot with modified axis orientation");

## Test correct handle type (line) returned by polar.
%!test
%! hf = figure ("visible", "off");
%! unwind_protect
%!  hax = gca ();
%!  h = polar (hax, 1, 2);
%!  h_data = get (h);
%!  assert (h_data.parent, hax);
%!  assert (h_data.type, "line");
%!
%!  h = polar (hax, [1 2 3; 4 5 6], [1 2 3; 4 5 6]);
%!  h_data = get (h);
%!  assert (numel (h_data), 3);
%!  assert (h_data(1).parent, hax);
%!  assert (isequal (h_data.parent));
%!  assert (all (strcmp ({h_data.type}, "line")));
%! unwind_protect_cleanup
%!   close (hf);
%! end_unwind_protect

## Test scalar/vector/matrix data inputs
%!test # Scalar inputs
%! hf = figure ("visible", "off");
%! hax = gca ();
%! unwind_protect
%!   h = polar (hax, 0, 0);
%!   linedata = get (h);
%!   assert (linedata.xdata, 0);
%!   assert (linedata.ydata, 0);
%!   assert (linedata.zdata, []);
%!   h = polar (hax, 1, 2);
%!   linedata = get (h);
%!   assert (linedata.xdata, 2 * cos (1), eps);
%!   assert (linedata.ydata, 2 * sin (1), eps);
%! unwind_protect_cleanup
%!   close (hf);
%! end_unwind_protect

%!test # Vector inputs and orientation independence
%! hf = figure ("visible", "off");
%! hax = gca ();
%! unwind_protect
%!   h = polar (hax, [1 2 3], [4 5 6]);
%!   linedata = get (h);
%!   assert (linedata.xdata, [4 5 6] .* cos ([1 2 3]), eps);
%!   assert (linedata.ydata, [4 5 6] .* sin ([1 2 3]), eps);
%!   assert (linedata.zdata, []);
%!   h = polar (hax, [1 2 3], [4 5 6]');
%!   linedata = get (h);
%!   assert (linedata.xdata, [4 5 6] .* cos ([1 2 3]), eps);
%!   assert (linedata.ydata, [4 5 6] .* sin ([1 2 3]), eps);
%!   assert (linedata.zdata, []);
%!   h = polar (hax, [1 2 3]', [4 5 6]);
%!   linedata = get (h);
%!   assert (linedata.xdata, [4 5 6] .* cos ([1 2 3]), eps);
%!   assert (linedata.ydata, [4 5 6] .* sin ([1 2 3]), eps);
%!   assert (linedata.zdata, []);
%!   h = polar (hax, [1 2 3]', [4 5 6]');
%!   linedata = get (h);
%!   assert (linedata.xdata, [4 5 6] .* cos ([1 2 3]), eps);
%!   assert (linedata.ydata, [4 5 6] .* sin ([1 2 3]), eps);
%!   assert (linedata.zdata, []);
%! unwind_protect_cleanup
%!   close (hf);
%! end_unwind_protect

%!test # Matrix inputs
%! t = [1 2 3; 4 5 6];
%! r = [7 8 9; 10 11 12];
%! hf = figure ("visible", "off");
%! hax = gca ();
%! unwind_protect
%!   h = polar (hax, t, r);
%!   linedata = get (h);
%!   assert (numel (linedata), 3);
%!   assert (vertcat (linedata.xdata)', r .* cos (t), eps);
%!   assert (vertcat (linedata.ydata)', r .* sin (t), eps);
%!   assert (isempty (vertcat (linedata.zdata)));
%! unwind_protect_cleanup
%!   close (hf);
%! end_unwind_protect

%!test # Mixed Vector/matrix inputs
%! tv1 = [1 2];
%! tv2 = [1 2 3];
%! tm = [1 2 3; 4 5 6];
%! rv1 = [7 8];
%! rv2 = [7 8 9];
%! rm = [7 8 9; 10 11 12];
%! hf = figure ("visible", "off");
%! hax = gca ();
%! unwind_protect
%!
%!   h = polar (hax, tv1, rm);
%!   linedata = get (h);
%!   assert (numel (linedata), 3);
%!   assert (vertcat (linedata.xdata)', rm .* cos (tv1'), eps);
%!   assert (vertcat (linedata.ydata)', rm .* sin (tv1'), eps);
%!   assert (isempty (vertcat (linedata.zdata)));
%!
%!   h = polar (hax, tv1', rm);  # Verify orientation independence.
%!   linedata = get (h);
%!   assert (numel (linedata), 3);
%!   assert (vertcat (linedata.xdata)', rm .* cos (tv1'), eps);
%!   assert (vertcat (linedata.ydata)', rm .* sin (tv1'), eps);
%!   assert (isempty (vertcat (linedata.zdata)));
%!
%!   h = polar (hax, tv2, rm);
%!   linedata = get (h);
%!   assert (numel (linedata), 2);
%!   assert (vertcat (linedata.xdata), rm .* cos (tv2), eps);
%!   assert (vertcat (linedata.ydata), rm .* sin (tv2), eps);
%!   assert (isempty (vertcat (linedata.zdata)));
%!
%!   h = polar (hax, tv2', rm);  # Verify orientation independence.
%!   linedata = get (h);
%!   assert (numel (linedata), 2);
%!   assert (vertcat (linedata.xdata), rm .* cos (tv2), eps);
%!   assert (vertcat (linedata.ydata), rm .* sin (tv2), eps);
%!   assert (isempty (vertcat (linedata.zdata)));
%!
%!   h = polar (hax, tm, rv1);
%!   linedata = get (h);
%!   assert (numel (linedata), 3);
%!   assert (vertcat (linedata.xdata)', rv1' .* cos (tm), eps);
%!   assert (vertcat (linedata.ydata)', rv1' .* sin (tm), eps);
%!   assert (isempty (vertcat (linedata.zdata)));
%!
%!   h = polar (hax, tm, rv1');  # Verify orientation independence.
%!   linedata = get (h);
%!   assert (vertcat (linedata.xdata)', rv1' .* cos (tm), eps);
%!   assert (vertcat (linedata.ydata)', rv1' .* sin (tm), eps);
%!   assert (isempty (vertcat (linedata.zdata)));
%!
%!   h = polar (hax, tm, rv2);
%!   linedata = get (h);
%!   assert (numel (linedata), 2);
%!   assert (vertcat (linedata.xdata), rv2 .* cos (tm), eps);
%!   assert (vertcat (linedata.ydata), rv2 .* sin (tm), eps);
%!   assert (isempty (vertcat (linedata.zdata)));
%!
%!   h = polar (hax, tm, rv2');  # Verify orientation independence.
%!   linedata = get (h);
%!   assert (numel (linedata), 2);
%!   assert (vertcat (linedata.xdata), rv2 .* cos (tm), eps);
%!   assert (vertcat (linedata.ydata), rv2 .* sin (tm), eps);
%!   assert (isempty (vertcat (linedata.zdata)));
%!
%! unwind_protect_cleanup
%!   close (hf);
%! end_unwind_protect

## Check that complex input produces identical output to (theta,rho) input
%!test
%! hf = figure ("visible", "off");
%! hax = gca ();
%! unwind_protect
%!   h = polar (hax, [1+2i, 3+4i]);
%!   haxcplx = get (hax);
%!   linecplx = get (h);
%!   h = polar (hax, [1, 3], [2, 4]);
%!   haxtr = get (hax);
%!   linetr = get (h);
%!
%!   haxtr.children = [];  # Clear child handles that should be unique.
%!   haxtr.xlabel= [];
%!   haxtr.ylabel= [];
%!   haxtr.zlabel= [];
%!   haxtr.title= [];
%!   haxcplx.children = [];
%!   haxcplx.xlabel = [];
%!   haxcplx.ylabel = [];
%!   haxcplx.zlabel = [];
%!   haxcplx.title = [];
%!
%!   assert (isequaln (haxcplx, haxtr));    # Check parent objects.
%!   assert (isequaln (linecplx, linetr));  # Check actual data objects.
%! unwind_protect_cleanup
%!   close (hf);
%! end_unwind_protect

##Test rtick, ttick being set - including the unlabeled 0 (bug #64991)
%!test <*64991>
%! hf = figure ("visible", "off");
%! hax = gca ();
%! unwind_protect
%!   polar (hax, [1 2 3], [4 5 6]);
%!   haxdata = get (hax);
%!   assert (haxdata.rtick, [0 2 4 6]);
%!   assert (haxdata.ttick, [0:30:330]);
%! unwind_protect_cleanup
%!   close (hf);
%! end_unwind_protect

## Test FMT string inputs
%!test
%! hf = figure ("visible", "off");
%! hax = gca ();
%! unwind_protect
%!   h = polar (hax, [1 2 3], [4 5 6]);
%!   linedata = get (h);
%!   assert (linedata.color, [0 0.447 0.741], eps);
%!   assert (linedata.marker, "none");
%!   assert (linedata.linestyle, "-");
%!   h = polar (hax, [1 2 3], [4 5 6], "r");
%!   linedata = get (h);
%!   assert (linedata.color, [1 0 0]);
%!   assert (linedata.marker, "none");
%!   assert (linedata.linestyle, "-");
%!   h = polar (hax, [1 2 3], [4 5 6], "--");
%!   linedata = get (h);
%!   assert (linedata.color, [0 0.447 0.741], eps);
%!   assert (linedata.marker, "none");
%!   assert (linedata.linestyle, "--");
%!   h = polar (hax, [1 2 3], [4 5 6], "*--r");
%!   linedata = get (h);
%!   assert (linedata.color, [1 0 0], eps);
%!   assert (linedata.marker, "*");
%!   assert (linedata.linestyle, "--");
%! unwind_protect_cleanup
%!   close (hf);
%! end_unwind_protect

## Test input validation
%!error <Invalid call> polar ()
%!test
%! hf = figure ("visible", "off");
%! unwind_protect
%!   hax = gca ();
%!   fail ("polar (hax, 1, 2, 3)", "FMT argument must be a string");
%!   fail ("polar (hax, cat (3, 1, 2, 3), [1 2 3])", "THETA and RHO must be 2-D objects");
%!   fail ("polar (hax, [1 2 3], cat (3, 1, 2, 3))", "THETA and RHO must be 2-D objects");
%!   fail ("polar (hax, 1, [1 2 3])", "Can't plot constant THETA with varying RHO");
%!   fail ("polar (hax, [1 2 3], 1)", "THETA and RHO vector lengths must match");
%!   fail ("polar (hax, [1 2 3],[1 2])", "THETA and RHO vector lengths must match");
%!   fail ("polar (hax, [1 2 3], [1 2; 3 4])", "THETA vector and RHO matrix sizes must match");
%!   fail ("polar (hax, [1 2; 3 4], [1 2 3])", "THETA matrix and RHO vector sizes must match");
%!   fail ("polar (hax, [1 2; 3 4], [1 2 3; 4 5 6])", "THETA and RHO matrix dimensions must match");
%!   h = polar (hax, 1, 2);  # Generates line object handle.
%!   fail ("polar (h, 1, 2)", "first argument must be axes handle");
%! unwind_protect_cleanup
%!   close (hf);
%! end_unwind_protect