Skip to main content
added 106 characters in body
Source Link
GameAlchemist
  • 1.4k
  • 7
  • 10

( Edit : the method above works only for square AABB, i'll have to think on how to improve it, sorry )

Fastest way is to :

  • A) test circle against rect's outer bounding circle -> reject if too far.
  • B) test circle against rect's inner bounding circle -> accept if near enough.
  • C) test that the outer point of the circle (on the line joining both centers) is in the AABB.

enter image description here

enter image description here

enter image description here To do that quickly , precompute inner, outer radius for your AABBs.

Some pseudo-code to illustrate :

var sqDistanceBetweenCenters = sqDistance ( AABB.center, Circle.center );
if (sqDistanceBetweenCenters > sq ( AABB.outerRadius + Circle.radius ) ) return false;
if (sqDistanceBetweenCenters < sq ( AABB.innerRadius + Circle.radius ) ) return true;
var c1c2Vect =  ( Circle.center - AABB.center ) . normalize(); 
var outerPoint = Circle.center + Circle.radius * c1c2Vect ;
return AABB.pointInRect(outerPoint);

In most cases they won't intersect so you have very few operations.
In quite some of the remaining cases they will intersect with the inner radius, so again few operations.

Fastest way is to :

  • A) test circle against rect's outer bounding circle -> reject if too far.
  • B) test circle against rect's inner bounding circle -> accept if near enough.
  • C) test that the outer point of the circle (on the line joining both centers) is in the AABB.

enter image description here

enter image description here

enter image description here To do that quickly , precompute inner, outer radius for your AABBs.

Some pseudo-code to illustrate :

var sqDistanceBetweenCenters = sqDistance ( AABB.center, Circle.center );
if (sqDistanceBetweenCenters > sq ( AABB.outerRadius + Circle.radius ) ) return false;
if (sqDistanceBetweenCenters < sq ( AABB.innerRadius + Circle.radius ) ) return true;
var c1c2Vect =  ( Circle.center - AABB.center ) . normalize(); 
var outerPoint = Circle.center + Circle.radius * c1c2Vect ;
return AABB.pointInRect(outerPoint);

In most cases they won't intersect so you have very few operations.
In quite some of the remaining cases they will intersect with the inner radius, so again few operations.

( Edit : the method above works only for square AABB, i'll have to think on how to improve it, sorry )

Fastest way is to :

  • A) test circle against rect's outer bounding circle -> reject if too far.
  • B) test circle against rect's inner bounding circle -> accept if near enough.
  • C) test that the outer point of the circle (on the line joining both centers) is in the AABB.

enter image description here

enter image description here

enter image description here To do that quickly , precompute inner, outer radius for your AABBs.

Some pseudo-code to illustrate :

var sqDistanceBetweenCenters = sqDistance ( AABB.center, Circle.center );
if (sqDistanceBetweenCenters > sq ( AABB.outerRadius + Circle.radius ) ) return false;
if (sqDistanceBetweenCenters < sq ( AABB.innerRadius + Circle.radius ) ) return true;
var c1c2Vect =  ( Circle.center - AABB.center ) . normalize(); 
var outerPoint = Circle.center + Circle.radius * c1c2Vect ;
return AABB.pointInRect(outerPoint);

In most cases they won't intersect so you have very few operations.
In quite some of the remaining cases they will intersect with the inner radius, so again few operations.

added 254 characters in body
Source Link
GameAlchemist
  • 1.4k
  • 7
  • 10

Fastest way is to :

  • A) test circle against rect's outer bounding circle -> reject if too far.
  • B) test circle against rect's inner bounding circle -> accept if near enough.
  • C) test that the outer point of the circle (on the line joining both centers) is in the AABB.

Toenter image description here

enter image description here

enter image description here To do that quickly , precompute inner, outer radius for your AABBs.

Some pseudo-code to illustrate :

var sqDistanceBetweenCenters = sqDistance ( AABB.center, Circle.center );
if (sqDistanceBetweenCenters > sq ( AABB.outerRadius + Circle.radius ) ) return false;
if (sqDistanceBetweenCenters < sq ( AABB.innerRadius + Circle.radius ) ) return true;
var c1c2Vect =  ( Circle.center - AABB.center ) . normalize(); 
var outerPoint = Circle.center + Circle.radius * c1c2Vect ;
return AABB.pointInRect(outerPoint);

In most cases they won't intersect so you have very few operations.
In quite some of the remaining cases they will intersect with the inner radius, so again few operations.

Fastest way is to :

  • test circle against rect's outer bounding circle -> reject if too far.
  • test circle against rect's inner bounding circle -> accept if near enough.
  • test that the outer point of the circle (on the line joining both centers) is in the AABB.

To do that quickly , precompute inner, outer radius for your AABBs.

Some pseudo-code to illustrate :

var sqDistanceBetweenCenters = sqDistance ( AABB.center, Circle.center );
if (sqDistanceBetweenCenters > sq ( AABB.outerRadius + Circle.radius ) ) return false;
if (sqDistanceBetweenCenters < sq ( AABB.innerRadius + Circle.radius ) ) return true;
var c1c2Vect =  ( Circle.center - AABB.center ) . normalize(); 
var outerPoint = Circle.center + Circle.radius * c1c2Vect ;
return AABB.pointInRect(outerPoint);

In most cases they won't intersect so you have very few operations.
In quite some of the remaining cases they will intersect with the inner radius, so again few operations.

Fastest way is to :

  • A) test circle against rect's outer bounding circle -> reject if too far.
  • B) test circle against rect's inner bounding circle -> accept if near enough.
  • C) test that the outer point of the circle (on the line joining both centers) is in the AABB.

enter image description here

enter image description here

enter image description here To do that quickly , precompute inner, outer radius for your AABBs.

Some pseudo-code to illustrate :

var sqDistanceBetweenCenters = sqDistance ( AABB.center, Circle.center );
if (sqDistanceBetweenCenters > sq ( AABB.outerRadius + Circle.radius ) ) return false;
if (sqDistanceBetweenCenters < sq ( AABB.innerRadius + Circle.radius ) ) return true;
var c1c2Vect =  ( Circle.center - AABB.center ) . normalize(); 
var outerPoint = Circle.center + Circle.radius * c1c2Vect ;
return AABB.pointInRect(outerPoint);

In most cases they won't intersect so you have very few operations.
In quite some of the remaining cases they will intersect with the inner radius, so again few operations.

Source Link
GameAlchemist
  • 1.4k
  • 7
  • 10

Fastest way is to :

  • test circle against rect's outer bounding circle -> reject if too far.
  • test circle against rect's inner bounding circle -> accept if near enough.
  • test that the outer point of the circle (on the line joining both centers) is in the AABB.

To do that quickly , precompute inner, outer radius for your AABBs.

Some pseudo-code to illustrate :

var sqDistanceBetweenCenters = sqDistance ( AABB.center, Circle.center );
if (sqDistanceBetweenCenters > sq ( AABB.outerRadius + Circle.radius ) ) return false;
if (sqDistanceBetweenCenters < sq ( AABB.innerRadius + Circle.radius ) ) return true;
var c1c2Vect =  ( Circle.center - AABB.center ) . normalize(); 
var outerPoint = Circle.center + Circle.radius * c1c2Vect ;
return AABB.pointInRect(outerPoint);

In most cases they won't intersect so you have very few operations.
In quite some of the remaining cases they will intersect with the inner radius, so again few operations.