Circle-Rectangle collision detection (intersection)

前端 未结 24 1383
无人共我
无人共我 2020-11-22 02:55

How can I tell whether a circle and a rectangle intersect in 2D Euclidean space? (i.e. classic 2D geometry)

24条回答
  •  渐次进展
    2020-11-22 03:18

    1. do a pre-check whether a circle fully encapsulating the rectangle collides with the circle.
    2. check for rectangle corners within the circle.
    3. For each edge, see if there is a line intersection with the circle. Project the center point C onto the line AB to get a point D. If the length of CD is less than radius, there was a collision.
        projectionScalar=dot(AC,AB)/(mag(AC)*mag(AB));
        if(projectionScalar>=0 && projectionScalar<=1) {
            D=A+AB*projectionScalar;
            CD=D-C;
            if(mag(CD)

提交回复
热议问题