Possible Duplicate:
Circle-Rectangle collision detection (intersection)
Collision detection between a line and a circle in JavaScript
This is more pseudo than actual working code...
var dX = rectanlge.x - circle.x; var dY = rectangle.y - circle.y; var distance = Math.sqrt((dX*dX)+(dY*dY)); if(distance < circle.radius){ //Collision } This is all I have so far to detect whether a circle and rectangle collide in a canvas animation. I am clearly going wrong, can some one point me in the right direction?
rectangles = []; var rectangle = function(x,y,width,height){ this.x = x; this.y = y; this.width = width; this.height = height; }; Then I would loop through this array
rectangledefined?rectanlgeinstead ofrectangle.