Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you have two bounding boxes (i.e. rectangles) with some arbitrary orientation (which I assume means some "rotation"), then I would do the following:</p> <ul> <li>Starting at an initial position (where I assume the bounding boxes are not intersecting), translate each box forward based on its velocity (however you're applying movements over time).</li> <li>Find the coordinates of the corners of each translated bounding box. These 4 coordinates define the endpoints of the 4 line segments that make up the edges of the bounding box.</li> <li>For bounding box #1, test for an intersection between each of its line segments and the 4 line segments of bounding box #2. You can do this using standard equations for computing the intersection point of two lines, as discussed <a href="http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/" rel="nofollow noreferrer">here</a>, for example.</li> <li>If there was an intersection, figure out the fraction of a move that was successful using the coordinates of the intersection points and the known translation you applied.</li> <li>Repeat the above steps for each update.</li> </ul> <p><strong>EDIT:</strong> A rough pseudocode (incorporating what was discussed in the comments) would look as follows:</p> <pre><code>...test for intersections between the OBB edges... if any intersections are found{ ...run code for when OBBs are partially overlapping... }else{ P = line segment whose endpoints are the OBB centers; ...test for intersections between P and OBB edges... if P intersects edges of both OBBs{ ...run code for when OBBs are not touching... }else{ ...run code for when one OBB is completely inside the other... } } </code></pre>
 

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