2D Polygon Collision Detection

前端 未结 4 1795
没有蜡笔的小新
没有蜡笔的小新 2020-12-31 10:36

Does anyone know a simple way to check if two polygons, especially rectangles, are colliding? I found a simple way to see if two are touching by just checking if a

4条回答
  •  情书的邮戳
    2020-12-31 11:05

    Check out http://www.metanetsoftware.com/technique/tutorialA.html

    That site helped me infinitely when developing my own collision detection routines. Depending on the amount of available processing power, you can do just about anything you want in terms of collision accuracy. Starting with the least processor intensive:

    1) Bounding box: Good for rectangular shapes and quick to boot. All you need to know is the (x, y) position of the object as well as its width and height.

    2) Separating Axis Theorem (SAT): Able to handle more complex shapes and is fairly intuitive.

    3) SAT with Voronoi Regions (VR): Uses information on which vertex of any given polygon is closest to in order to reduce the total number of computations.

    All of the above is explained in-depth in the above link. It should be noted that, thus far, the methods mentioned are most effective for convex polygons. If you wanted to go into absurd levels of accuracy, you start moving into things like bitmap testing which is horrendously slow and generally overkill for almost anything.

提交回复
热议问题