Is there a way to find the intersection of two rectangles given their current velocity and position in constant time?

239 Views Asked by At

Suppose I have two rectangles, let's define them as $R_1$ and $R_2$, which each contain a length and width. Given the headings $\theta_1$ and $\theta_2$ respectively, as well as the coordinates $x_1, y_1, x_2, y_2$ and constant velocity $v_1, v_2$ is there a feasible way to determine the collision points in constant or logarithmic time?

My idea so far is as follows: we can perform ternary search on the first collision time - assuming that the collisions are unimodal, which means that there will be a range $[a, b]$ such that the rectangles would be intersecting each other, which I have no proof for. Then, calculate the first time, and thus intersection points as well as locations from there. The running time of this algorithm would be $\mathcal{O}(\log N)$.

A setup of the rectangles

1

There are 1 best solutions below

1
On

Use a coordinate system where the larger rectangle is always $(\pm 1, \pm 1)$.

Then you only need to check if any of the four vertices of the smaller rectangle ever intersect with that square in that coordinate system.