Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

circle rect collision

//Javascript
function rect_circle_collision(center, r, v1, v2){ //v1 and v2 must be opposite vertices
  let closest = {
    x : max(v1.x, min(center.x, v2.x)),
    y : max(v1.y, min(center.y, v2.y))
  };
  return (closest.x - center.x) ** 2 + (closest.y - center.y) ** 2 <= r; 
}
 
PREVIOUS NEXT
Tagged: #circle #rect #collision
ADD COMMENT
Topic
Name
5+2 =