{"id":2578,"date":"2010-07-16T11:36:43","date_gmt":"2010-07-16T11:36:43","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2010\/07\/16\/sun_positionm\/"},"modified":"2022-08-24T16:57:09","modified_gmt":"2022-08-24T20:57:09","slug":"sun_positionm","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2010\/07\/16\/sun_positionm\/","title":{"rendered":"sun_position.m"},"content":{"rendered":"<div class=\"alert alert-info\"> <span class=\"alert_icon icon-alert-info-reverse\"><\/span><p class=\"alert_heading\"><strong>Note<\/strong><\/p><p>The file submission referenced in this post is no longer available on File Exchange.<\/p><\/div>\r\n<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 sun_position.m by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/12685\">Vincent Roy<\/a>.\r\n      <\/p>\r\n   <\/introduction>\r\n   <p>Here at MathWorks headquarters in Natick, MA we are entering the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Dog_Days\">dog days of Summer<\/a>. Like many others to help stay cool during the day I minimize unwanted solar heating through windows with shades and blinds.\r\n      Of course that conserves energy which also saves money!\r\n   <\/p>\r\n\r\n   <p>From a technical aspect you can calculate the position of the Sun. Given a place and time <tt>sun_position<\/tt> does the math for you. For example, where is my Noon Sun today?\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">here.longitude = -71.34993; <span style=\"color: #228B22\">%deg<\/span>\r\nhere.latitude  =  42.30013; <span style=\"color: #228B22\">%deg<\/span>\r\nhere.altitude  =  55;       <span style=\"color: #228B22\">%m<\/span>\r\nnoonToday = datenum(<span style=\"color: #A020F0\">'2010-07-16 12:00'<\/span>);\r\nsun_position(noonToday,here)<\/pre><pre style=\"font-style:oblique\">ans = \r\n     zenith: 63.368\r\n    azimuth: 84.585\r\n<\/pre><p>Wikepedia helped get my head around what <a href=\"http:\/\/en.wikipedia.org\/wiki\/Zenith\">zenith<\/a> and <a href=\"http:\/\/en.wikipedia.org\/wiki\/Azimuth\">azimuth<\/a> mean.\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/4\/47\/Zenith-Nadir-Horizon.svg\/300px-Zenith-Nadir-Horizon.svg.png\"> <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/3\/38\/Azimuth_%28PSF%29_2.svg\/350px-Azimuth_%28PSF%29_2.svg.png\"> <\/p>\r\n   <p>Thanks to Vincent for making that so easy for me to use. His submission also has a lot of good feedback from others. I appreciate submissions like this where people collaboratively make good work even better as the \"updates\"\r\n      section makes clear. Keep up the great work, everyone!\r\n   <\/p>\r\n   <p>Do you use solar calculations? Tell us about it <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2578#respond\">here<\/a>.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_cea563a2d2cc409498b0f225617d7ef4() {\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='cea563a2d2cc409498b0f225617d7ef4 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' cea563a2d2cc409498b0f225617d7ef4';\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 2010 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_cea563a2d2cc409498b0f225617d7ef4()\"><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\ncea563a2d2cc409498b0f225617d7ef4 ##### 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\/4605-sunposition-m sun_position.m> \r\n% by \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/12685 Vincent Roy>.\r\n%%\r\n% Here at MathWorks headquarters in Natick, MA we are entering the \r\n% <http:\/\/en.wikipedia.org\/wiki\/Dog_Days dog days of Summer>. Like many\r\n% others to help stay cool during the day I minimize unwanted solar heating\r\n% through windows with shades and blinds. Of course that conserves energy\r\n% which also saves money! \r\n%%\r\n% <<http:\/\/www.windowblindstips.com\/wp-content\/uploads\/window-blind-pulls.jpg>>\r\n%%\r\n% From a technical aspect you can calculate the position of the Sun. Given\r\n% a place and time |sun_position| does the math for you. For example, where\r\n% is my Noon Sun today?\r\nhere.longitude = -71.34993; %deg\r\nhere.latitude  =  42.30013; %deg\r\nhere.altitude  =  55;       %m\r\nnoonToday = datenum('2010-07-16 12:00');\r\nsun_position(noonToday,here)\r\n%%\r\n% Wikepedia helped get my head around what \r\n% <http:\/\/en.wikipedia.org\/wiki\/Zenith zenith>\r\n% and \r\n% <http:\/\/en.wikipedia.org\/wiki\/Azimuth azimuth>\r\n% mean.\r\n%\r\n% <<http:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/4\/47\/Zenith-Nadir-Horizon.svg\/300px-Zenith-Nadir-Horizon.svg.png>> \r\n%\r\n% <<http:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/3\/38\/Azimuth_%28PSF%29_2.svg\/350px-Azimuth_%28PSF%29_2.svg.png>>\r\n%%\r\n% Thanks to Vincent for making that so easy for me to use. His submission\r\n% also has a lot of good \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/4605-sunposition-m#feedback feedback>\r\n% from others. I appreciate submissions like this where people\r\n% collaboratively make good work even better as the \"updates\" section makes\r\n% clear. Keep up the great work, everyone!\r\n\r\n%%\r\n% Do you use solar calculations? Tell us about it \r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2578#respond here>.\r\n##### SOURCE END ##### cea563a2d2cc409498b0f225617d7ef4\r\n-->","protected":false},"excerpt":{"rendered":"<p> NoteThe file submission referenced in this post is no longer available on File Exchange.\r\n\r\n   \r\n      Bob's pick this week is sun_position.m by Vincent Roy.\r\n      \r\n   \r\n   Here at MathWorks... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2010\/07\/16\/sun_positionm\/\">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\/2578"}],"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=2578"}],"version-history":[{"count":3,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2578\/revisions"}],"predecessor-version":[{"id":16172,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2578\/revisions\/16172"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}