Ball to Ball Collision - Detection and Handling

前端 未结 14 1406
逝去的感伤
逝去的感伤 2020-11-22 05:29

With the help of the Stack Overflow community I\'ve written a pretty basic-but fun physics simulator.

\"alt

14条回答
  •  情歌与酒
    2020-11-22 05:42

    Improving the solution to detect circle with circle collision detection given within the question:

    float dx = circle1.x - circle2.x,
          dy = circle1.y - circle2.y,
           r = circle1.r + circle2.r;
    return (dx * dx + dy * dy <= r * r);
    

    It avoids the unnecessary "if with two returns" and the use of more variables than necessary.

提交回复
热议问题