0

I'm looking for a simplified algorithm to test for intersection between an OBB and a sphere. There are algorithms out there that I've seen, but most of them over-complicate things because they need to account for all 3 axes of rotation on the OBB. In my case, the OBB rotates only on the Z axis, so I feel like something in between the standard Circle/Rotated Rectangle algorithm and the Sphere/OBB algorithms would probably be more optimal.

For reference, the OBB is stored as a Vector3 for the center, another Vector3 for the half-dimensions, and a Matrix33 for the orientation - keeping in mind that we can guarantee that when translated to Euler rotation, two of the axes will be 0, and only the Z axis will change. The sphere is just a Vector3 for the center and a float for radius.

I suspect such a thing may be possible by simply figuring out the radii of the cross sections of the sphere that correspond to the top and bottom of the OBB, and also the maximum radius of the sphere if its center is between the top and bottom, and then running a Circle/Rotated Rectangle collision check on each of these two (or three) radii. What I'm not sure of is if this will be easier (in terms of both coding and performance) than the full Sphere/OBB test.

(I'm going to leave this language-agnostic. I'm working in C++, but I'll accept an algorithm in any common language provided it's simple enough to translate to C++.)

Darrel Hoffman
  • 4,436
  • 6
  • 29
  • 41

1 Answers1

0

Yes, there exists rather simple method for finding distance (and intersection) between rectangle and circle. It could be easily extended for 3D case and for rotated box.

In your case (rotation only about Z-axis) it is simpler to apply simple coordinate transformation - rotate sphere center about this axis - and use approach intended for axis-aligned box.

In common case one would calculate needed distance through lengths of projections of vector BoxCenter-SphereCenter onto edge vectors, but I believe that rotation of one point + simple calculations is more effective.

Community
  • 1
  • 1
MBo
  • 77,366
  • 5
  • 53
  • 86