{"id":2499,"date":"2009-11-27T13:49:44","date_gmt":"2009-11-27T13:49:44","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2009\/11\/27\/degrees-and-radians\/"},"modified":"2009-11-27T13:49:44","modified_gmt":"2009-11-27T13:49:44","slug":"degrees-and-radians","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2009\/11\/27\/degrees-and-radians\/","title":{"rendered":"degrees and radians"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/5021\">Bob<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/3263-degrees-and-radians\">degrees and radians<\/a>  by Richard Medlock.\r\n      <\/p>\r\n   <\/introduction>\r\n   <p>These two helper functions are simple but useful. I don't know how many times I have needed to convert between radians and\r\n      degrees over the years. (Hint: a lot!) For example, sometimes defining a frequency value in Hertz is more convenient for humans,\r\n      but conversion to radian frequency is generally needed by the computer at some point.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">f0 = 60;         <span style=\"color: #228B22\">%frequency (Hz)<\/span>\r\nw0 = f0*pi\/180;  <span style=\"color: #228B22\">%natural frequency (rad)<\/span><\/pre><p>The conversion factor is not difficult, but it can be a workflow distraction nonetheless. Hence, Richard's utility functions\r\n      to do the conversion for you.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">radians(180)<\/pre><pre style=\"font-style:oblique\">ans =\r\n       3.1416\r\n<\/pre><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">degrees(pi\/3)<\/pre><pre style=\"font-style:oblique\">ans =\r\n           60\r\n<\/pre><p>I tend to dislike magic numbers, particularly in complex calculations. So I can see helper functions like these making code\r\n      more readable. Magic numbers that appear many times throughout a program can also be prone to logical errors if I mistype\r\n      a value somewhere. Those types of problems can be difficult to track down. Also, having conversion code centralized in one\r\n      place can pay dividends in reusability and testability.\r\n   <\/p>\r\n   <p><a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2499#respond\">Comments?<\/a><\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_a9a06a9f6b274121b7643e7c64905e2f() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='a9a06a9f6b274121b7643e7c64905e2f ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' a9a06a9f6b274121b7643e7c64905e2f';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Robert Bemis';\r\n        copyright = 'Copyright 2009 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_a9a06a9f6b274121b7643e7c64905e2f()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.10<br><\/p>\r\n<\/div>\r\n<!--\r\na9a06a9f6b274121b7643e7c64905e2f ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/5021 Bob>'s \r\n% pick this week is \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/3263-degrees-and-radians degrees and radians> \r\n%  by Richard Medlock.\r\n%%\r\n% These two helper functions are simple but useful. I don't know how many\r\n% times I have needed to convert between radians and degrees over the years.\r\n% (Hint: a lot!) For example, sometimes defining a frequency value in Hertz\r\n% is more convenient for humans, but conversion to radian frequency is\r\n% generally needed by the computer at some point. \r\nf0 = 60;         %frequency (Hz)\r\nw0 = f0*pi\/180;  %natural frequency (rad)\r\n%%\r\n% The conversion factor is not difficult, but it can be a workflow\r\n% distraction nonetheless. Hence, Richard's utility functions to do the\r\n% conversion for you.  \r\nradians(180)\r\n%%\r\ndegrees(pi\/3)\r\n%%\r\n% I tend to dislike magic numbers, particularly in complex calculations. So I\r\n% can see helper functions like these making code more readable. Magic\r\n% numbers that appear many times throughout a program can also be prone to\r\n% logical errors if I mistype a value somewhere. Those types of problems can\r\n% be difficult to track down. Also, having conversion code centralized in one\r\n% place can pay dividends in reusability and testability.\r\n%%\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2499#respond Comments?>\r\n\r\n##### SOURCE END ##### a9a06a9f6b274121b7643e7c64905e2f\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n      Bob's pick this week is degrees and radians  by Richard Medlock.\r\n      \r\n   \r\n   These two helper functions are simple but useful. I don't know how many times I have needed... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2009\/11\/27\/degrees-and-radians\/\">read more >><\/a><\/p>","protected":false},"author":46,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2499"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/46"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2499"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2499\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}