c++ - Collision between circle shape and rectangle -
this question has answer here:
i want detect collision between circle shape , rectangle shape, dont know how.
i know how detect collision between circle circle using pythagorean theorem is:
(x2 - x1)^2 + (y2 - y1)^2 - (r2 + r1) , math detect collision
between circle shape , rectangle shape in c or c++ programming language.
in collision detection beneficial first detect collisions between simple objects , specialise more complex one. called broad-phase , narrow-phase collision detection. idea using simpler algorithm rule out collisions first makes process faster when objects can proven trivially not colliding.
you model objects circles or boxes encompass the, potentially more complex, true shape. if find these objects colliding can use more complex algorithm check collisions.
it known that, convex objects, if 2 objects not colliding can find plane between them. known separating axis theorem. since both circle , square convex can use design algorithm detect collisions between them.
you can first search simple planes, such parallel edges of square , tangents circle. choice plane tangent circle on line between 2 centres of objects, followed line between centre of circle , each corner.
once have found separating plane objects can't colliding , can stop searching.
hope helps.
(a detailed explanation of application of can found here: http://www.metanetsoftware.com/technique/tutoriala.html#section1)
Comments
Post a Comment