Rectangle in 3D collision test

Started by
0 comments, last by Daniel Benmergui 23 years, 3 months ago
Does anyone know any good tutorials on how to compute if two rectangles in 3D (i mean, like a cube but with rectangular shape) intersects? It is enough with knowing if the collided, no need to compute the actual intersection... Thanks! Daniel.
Advertisement
      bool hit(all the arguments..){if (((x1-xs1<x2-xs2 && x1+xs1>x2-xs2) || (x1-xs1<x2+xs2 && x1+xs1>x2+xs2) || (x1-xs1>x2-xs2 && x1+xs1<x2+xs2)) &&((y1-ys1<y2-ys2 && y1+ys1>y2-ys2) || (y1-ys1<y2+ys2 && y1+ys1>y2+ys2) || (y1-ys1>y2-ys2 && y1+ys1<y2+ys2)) &&((z1-zs1<z2-zs2 && z1+zs1>z2-zs2) || (z1-zs1<z2+zs2 && z1+zs1>z2+zs2) || (z1-zs1>z2-zs2 && z1+zs1<z2+zs2)) &&) return true;return false;}      


y1=box 1, y coordinate to the center
ys1=box 1, "y size" (height)
x2=box 2, x coordinate to the center
etc.

Didn't try it and just wrote it.. So if it works might be a bit questionable . Of course the algo only works for axis-aligned "3d-rectangles" but I guess that's what your're looking for anyway.

Edited by - Hans on January 15, 2001 4:47:51 PM

This topic is closed to new replies.

Advertisement