   Circle intercepting a rectangle check (fast with no floating point)
  I'm working on a 2D racing game for devices with no floating point support.I've been using rectangles for all collison detection so far but would like to improve it because some of the objects in the game are round such as marbles.So what i would like to do is use rectangles (bounding boxes) for the marble first because it is so fast. If there is a collison between the two boxes then do a check using the slow(er) circle and rectangle intercept check.Do any of you know of a simple formula that would be suitable for such a constrained device? i could use 314 as pie and divide by 100 later on if its needed in the formula.Thanks for your help.Woody   
  Just use Pythagorean Theorem to get distance from point x,y to axis-aligned rectangle with corners x1y1 x2y2 that x2>x1 and y2>y1 ,let circle radius is circle_r  :int r2=0;if(x>x2){r2+=(x-x2)*(x-x2);}elseif(x<x1){r2+=(x-x1)*(x-x1);}if(y>y2){r2+=(y-y2)*(y-y2);}elseif(y<y1){r2+=(y-y1)*(y-y1);}return r2<=circle_r*circle_r;If done without floating point, you might need to be careful with overflows. (if you use 32 bit system, overflows shouldn't be a problem for distances below 30k)If you might get problems with overflow due to big distance, then, you canint r2=0;if(x>x2){if((x-x2)>circle_r)return false; r2+=(x-x2)*(x-x2);}elseif(x<x1){if((x1-x)>circle_r)return false; r2+=(x1-x)*(x1-x);}if(y>y2){if((y-y2)>circle_r)return false; r2+=(y-y2)*(y-y2);}elseif(y<y1){if((y1-y)>circle_r)return false; r2+=(y1-y)*(y1-y);}return r2<=circle_r*circle_r;, that shouldn't overflow unless circle radius is very big.(and if compiler you use sucks, you can manually do some common subexpression elimination)   ;  Just work with squares of distances rather than distances themselves.  This will save you the trouble of taking square roots.I suppose that one idea is first to use your rectangle routines to figure out which side of the incoming rectangle is the culprit, then make a few computations to find squares of distances for the endpoints of the side and the point closest to the circle center.   Let y = m x + b be the equation of a line forming the side of a rectangle with endpoints (x0,y0),(x1,y1)Let (xc,yc) be the center of the circleThe square of the distance from a corner to the center is (xc-x0)^2 + (yc-y0)^2The point on the side line closest to the center has x coordinate :-(b m) + xc + m ycx -> ------------------ 2 1 + mthe square of the distance at that point is:2(b + m xc - yc)----------------21 + mSo, I suppose the algorithm is (1) if the corners are close, it hits.  (2) if the corners don't hit, then does another point hit? (3) if another point hits, then is it's x value between the corners?Just an ideaC.   