Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, instead of thinking of two rectangles moving with speed <code>(x1, y1)</code> and <code>(x2, y2)</code> respectively, you may fix one of them (set its speed to <code>(0, 0)</code> ) and think of another one moving with speed <code>(x2 - x1, y2 - y1)</code>.</p> <p>This way, the situation looks like one rectangle is immovable, and another one is passing by, possibly hitting the first.</p> <ul> <li>Assuming you don't have any angular velocity</li> </ul> <p><img src="https://i.stack.imgur.com/WlC7D.png" alt="enter image description here"></p> <p>Not hard to see, that you can then intersect 4 trajectories of a second rectangle (they are rays starting from different corners of a bounding box in <code>(x2 - x1, y2 - y1)</code> direction) with 4 sides of the first rectangle, standing still. Then you'll have to do the same vice versa - find the intersection of a first rectangle moving in reverse direction - <code>(-(x2 - x1), -(y2 - y1))</code> with 4 sides of a second rectangle. Choose the minimum distance between the all intersection points you've found (there might be 0-8 of them) and you're done.</p> <p>Don't forget to consider many special cases - when the sides of both rectangles are parallel, when there's no intersection at all etc.</p> <p>Note, this all is done in <code>O(1)</code> time, though the calculations are quite complex - 32 intersections of a ray and a segment.</p> <ul> <li>If you really wish your rectangles to rotate with some speed, I would suggest considering what @comingstorm has said: this is a problem of finding roots of a non-linear equation, however, even in such case, if you have a limited angular speed of your rectangles, you may split the task into a series of <a href="http://en.wikipedia.org/wiki/Ternary_search" rel="nofollow noreferrer">ternary search</a> subtasks, though I suppose this is just one of possible methods of solving non-linear problems.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload