Puzzler: Overlapping rectangles
Today’s challenge is one where you need to figure out if two rectangles have a non-zero area of overlap.
The rectangles will be specified as follows:
Just fill in your part of the code until you get the binary variable overlap defined.
ax = sort(rand(1,2));
ay = sort(rand(1,2));
bx = sort(rand(1,2));
by = sort(rand(1,2));
clf
rectangle('position',[ax(1) ay(1) diff(ax) diff(ay)], 'edgecolor', 'r')
hold on
rectangle('position',[bx(1) by(1) diff(bx) diff(by)], 'edgecolor', 'k')
axis equal
%your code here
overlap = %1 for overlap, 0 for non-overlapping
When you post your code in the comments, please use the tags
<pre> <code>
all the code so someone can just copy and paste it from the comments.
</code> </pre>
My solution is already posted.
- 범주:
- Puzzler
댓글
댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.