Yes, that's the easy part, and uses a lookup table.

The hard part is resolving the collision. How far in x and y does it need to be pushed to resolve the overlap, and how do you resolve the velocity constraint caused by the contact between the two surfaces.

Off the top of my head, it works like this:

**Code:**

delta.x = pos0.x - pos1.x

delta.y = pos0.y - pos1.y

dist_sq = delta.x*delta.x + delta.y*delta.y

if(dist_sq < radius_sq){

// Fix distance with projection.

projection_coef = radius/math.sqrt(dist_sq) - 1

pos0.x += delta * projection_coef

pos0.y += delta * projection_coef

// Fix velocity constraint

n.x = delta.x/sqrt(dist_sq);

n.y = delta.y/sqrt(dist_sq);

vn = max(0, vel.x*n.x + vel.y*n.y);

vel.x -= n.x*vn;

vel.y -= n.y*vn;

}

The squares are calculated with tables. The projection coef is looked up from a table. 'delta' only has 4 bits, so those multiplies are unrolled and shortened. 'n', the collision normal, isn't really ever calculated. It's assumed to be close to delta/8, and so the last 4 multiplies are optimized 16x3 bit multiplies.