{"id":298,"date":"2009-05-28T17:02:33","date_gmt":"2009-05-29T00:02:33","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=1451"},"modified":"2009-05-28T17:02:33","modified_gmt":"2009-05-29T00:02:33","slug":"difference-between-two-angles","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=298","title":{"rendered":"Difference Between Two Angles"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n\/\/ from http:\/\/codebase.dbp-site.com\/code\/find-difference-between-two-angles-25\r\nfunction angleDifference(angle0:Number, angle1:Number):Number{\r\n\treturn Math.abs((angle0 + 180 -  angle1) % 360 - 180);\r\n}\r\n\r\ntrace(&quot;get the angle between:&quot;);\r\ntrace(&quot;350 and 10 =&quot;, angleDifference(350, 10));\r\ntrace(&quot;180 and -1 =&quot;, angleDifference(180, -1));\r\ntrace(&quot;-10 and 5 =&quot;, angleDifference(-10, 5));\r\ntrace(&quot;725 and -45 =&quot;, angleDifference(725, -45));\r\n\/* outputs:\r\nget the angle between:\r\n350 and 10 =  20\r\n180 and -1 =  179\r\n-10 and 5 =  15\r\n725 and -45 =  50\r\n*\/\r\n<\/pre>\n<p>This snippet shows an easy way to find the difference between two angles. The tricky part about doing this is finding the difference between something like 350 and 1 (which should be 11).<\/p>\n<p>Over the years I have done this a few different ways &#8211; I needed it for something today and realized that my way was a tad clunky (had a little redundant logic) &#8211; So with a quick google search I found <a href=\"http:\/\/codebase.dbp-site.com\/code\/find-difference-between-two-angles-25\" target=\"blank\">a more elegant solution<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ from http:\/\/codebase.dbp-site.com\/code\/find-difference-between-two-angles-25 function angleDifference(angle0:Number, angle1:Number):Number{ return Math.abs((angle0 + 180 &#8211; angle1) % 360 &#8211; 180); } trace(&quot;get the angle between:&quot;); trace(&quot;350 and 10 =&quot;, angleDifference(350, 10)); trace(&quot;180 and -1 =&quot;, angleDifference(180, -1)); trace(&quot;-10 and 5 =&quot;, angleDifference(-10, 5)); trace(&quot;725 and -45 =&quot;, angleDifference(725, -45)); \/* outputs: get the angle between: 350 and 10 = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[121,94,13],"tags":[3,4],"class_list":["post-298","post","type-post","status-publish","format-standard","hentry","category-math","category-misc","category-motion","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/298","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=298"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/298\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}