{"id":2248,"date":"2008-07-14T09:56:25","date_gmt":"2008-07-14T14:56:25","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2008\/07\/14\/puzzler-overlapping-rectangles\/"},"modified":"2008-07-17T14:53:56","modified_gmt":"2008-07-17T19:53:56","slug":"puzzler-overlapping-rectangles","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2008\/07\/14\/puzzler-overlapping-rectangles\/","title":{"rendered":"Puzzler: Overlapping rectangles"},"content":{"rendered":"<p>Today&#8217;s challenge is one where you need to figure out if two rectangles have a non-zero area of overlap.<\/p>\n<p>The rectangles will be specified as follows:<\/p>\n<p><img src='https:\/\/blogs.mathworks.com\/pick\/..\/images\/pick\/puzzlerrect.jpg' alt='puzzlerrect.jpg' \/><\/p>\n<p>Just fill in your part of the code until you get the binary variable overlap defined.<\/p>\n<pre>\r\n<code>ax = sort(rand(1,2));\r\nay = sort(rand(1,2));\r\nbx = sort(rand(1,2));\r\nby = sort(rand(1,2));\r\n\r\nclf\r\nrectangle('position',[ax(1) ay(1) diff(ax) diff(ay)], 'edgecolor', 'r')\r\nhold on\r\nrectangle('position',[bx(1) by(1) diff(bx) diff(by)], 'edgecolor', 'k')\r\naxis equal\r\n\r\n\r\n%your code here\r\n\r\noverlap = %1 for overlap, 0 for non-overlapping<\/code><\/pre>\n<p>When you post your code in the comments, please use the tags<\/p>\n<pre><code>\r\n&lt;pre> &lt;code>\r\n\r\nall the code so someone can just copy and paste it from the comments.\r\n\r\n&lt;\/code> &lt;\/pre>\r\n<\/code><\/pre>\n<p>My solution is already posted.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today&#8217;s challenge is one where you need to figure out if two rectangles have a non-zero area of overlap.<br \/>\nThe rectangles will be specified as follows:<\/p>\n<p>Just fill in your part of the code until&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2008\/07\/14\/puzzler-overlapping-rectangles\/\">read more >><\/a><\/p>\n","protected":false},"author":68,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2248"}],"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\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2248"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2248\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}