Skip to content

Instantly share code, notes, and snippets.

@ardcore
Created February 6, 2011 22:32
Show Gist options
  • Save ardcore/813784 to your computer and use it in GitHub Desktop.
Save ardcore/813784 to your computer and use it in GitHub Desktop.
var sth1 = {}, sth2 = {};
sth1.x = 10; // x pos
sth1.y = 10; // y pos
sth1.r = 10; // radius
sth2.x = 15; // x pos
sth2.y = 15; // y pos
sth2.r = 10; // radius
function testCircleCollision(obj1, obj2) {
var dist = Math.sqrt( Math.pow(obj2.x - obj1.x, 2) + Math.pow(obj2.y - obj1.y, 2) );
return dist < (obj1.r + obj2.r);
}
testCircleCollision(sth1, sth2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment