changeset 27921:4be05a32ad2f

polar.m: Use standard functions deg2rad and pol2cart to simplify code. * polar.m: Use standard functions deg2rad and pol2cart to simplify generation of radial lines in polar axes.
author Rik <rik@octave.org>
date Wed, 08 Jan 2020 12:31:16 -0800
parents 08630aedc41f
children a7c8d2d72120
files scripts/plot/draw/polar.m
diffstat 1 files changed, 8 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/draw/polar.m	Wed Jan 08 11:51:49 2020 -0800
+++ b/scripts/plot/draw/polar.m	Wed Jan 08 12:31:16 2020 -0800
@@ -331,7 +331,7 @@
   rtick = unique (get (hax, "rtick")(:)');
   rtick = rtick(rtick > 0);
   if (isempty (rtick))
-    rtick = [0.5 1];
+    rtick = [0.5, 1];
   endif
 
   ttick = unique (get (hax, "ttick")(:)');
@@ -374,18 +374,17 @@
         "parent", hg);
 
   ## Add radial lines
-  s = rtick(end) * sin (ttick * pi / 180);
-  c = rtick(end) * cos (ttick * pi / 180);
-  x = [zeros(1, numel (ttick)); c];
-  y = [zeros(1, numel (ttick)); s];
+  [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: This tm factor does not work as fontsize increases
-  tm = 1.08;
-  text (tm * c, tm * s, tticklabel, "horizontalalignment", "center",
-        tprops{:}, "parent", hg);
+  ## 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]);