Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been reading an article on Collision Detection and how to resolve it.

In the section describing an AABB vs Circle, it states:

The first step is to get the centre of the circle and project it on to the boundary of the AABB. Fortunately this is as easy as forming the vector V between AABB and circle and simply clamping it against the half extents of the AABB.

In the picture provided, it makes sense. You get the vector between the two objects, and then get the closest virtice to the circle and use that in your computation.

But, how DO you take the width/height into account to that new vector? He says "..simply clamping it against the half extends of the AABB"

Can anyone clarify what he means?

share|improve this question
up vote 3 down vote accepted

A clamp (or saturate) is constraining a value to be within a range of values, that is:

v' = max(low, min(high, v))

In this case, he wants you to clamp each component of the vector to the corresponding min/max on that axis.

x = max(-halfWidth,  min(halfWidth, circleX-boxX))
y = max(-halfHeight, min(halfHeight, circleY-boxY))

This will yield a point on the boundary of the box if the circle center is outside the box, or a point inside the box if the circle is inside.

By doing this, you can treat the box as a circle centered at the box center, with the circumference going through that point.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.