{"id":284,"date":"2008-07-14T09:56:25","date_gmt":"2008-07-14T14:56:25","guid":{"rendered":"https:\/\/blogs.mathworks.com\/videos\/2008\/07\/14\/puzzler-overlapping-rectangles\/"},"modified":"2008-07-14T09:56:25","modified_gmt":"2008-07-14T14:56:25","slug":"puzzler-overlapping-rectangles","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/videos\/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>\n<code>ax = sort(rand(1,2));\nay = sort(rand(1,2));\nbx = sort(rand(1,2));\nby = sort(rand(1,2));\n\nclf\nrectangle('position',[ax(1) ay(1) diff(ax) diff(ay)], 'edgecolor', 'r')\nhold on\nrectangle('position',[bx(1) by(1) diff(bx) diff(by)], 'edgecolor', 'k')\naxis equal\n\n\n%your code here\n\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>\n&lt;pre> &lt;code>\n\nall the code so someone can just copy and paste it from the comments.\n\n&lt;\/code> &lt;\/pre>\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\/videos\/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":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/284"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/comments?post=284"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/posts\/284\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/media?parent=284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/categories?post=284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/videos\/wp-json\/wp\/v2\/tags?post=284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}