How to detect if an ellipse intersects(collides with) a circle

后端 未结 10 2578
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-09 03:41

I want to improve a collision system.

Right now I detect if 2 irregular objects collide if their bounding rectangles collide.

I want to obtain the for recta

10条回答
  •  悲哀的现实
    2020-12-09 04:19

    An ellipse is defined a the set of points whose sum of the distance to point A and the distance to point B is constant e. (A and B are called the foci of the ellipse).

    All Points P, whose sum AP + BP is less than e, lie within the ellipse.

    A circle is defined as the set of points whose distance to point C is r.

    A simple test for intersection of circle and ellipse is following:

    Find
    P as the intersection of the circle and the line AC and
    Q as the intersection of the circle and the line BC.

    Circle and ellipse intersect (or the circle lies completely within the ellipse) if
    AP + BP <= e   or   AQ + BQ <= e

    alt text

    EDIT:

    After the comment of Martin DeMello and adapting my answer accordingly I thought more about the problem and found that the answer (with the 2nd check) still doesn't detect all intersections:

    If circle and ellipse are intersecting only very scarcely (just a little more than being tangent) P and Q will not lie within the ellipse:

    alt text

    So the test described above detects collision only if the overlap is "big enough". Maybe it is good enough for your practical purposes, although mathematically it is not perfect.

提交回复
热议问题