Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cube on Cube collision detection algorithm?

I'm trying to find the most efficient way to check if 2 arbitrarily sized cubes collide with each other. The sides of the cubes are not necessarily all equal in length (a box is possible). Given these constraints, how could I efficiently check if they collide? (each box has 24 verticies) Thanks

They are axis alligned

like image 865
jmasterx Avatar asked Dec 07 '22 01:12

jmasterx


1 Answers

Since both boxes are axis-aligned you can just compare their extents:

  return (a.max_x() >= b.min_x() and a.min_x() <= b.max_x())
     and (a.max_y() >= b.min_y() and a.min_y() <= b.max_y())
     and (a.max_z() >= b.min_z() and a.min_z() <= b.max_z())
like image 184
Laurence Gonsalves Avatar answered Jan 01 '23 01:01

Laurence Gonsalves