本文介绍了碰撞检测两个圆圈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 两个对象重叠时发生碰撞。也就是说,无论是全部还是部分,它们都占据相同的空间。由于这是我们的第一次碰撞练习,我们将限制我们检测两对圆之间碰撞的努力。 你应该重复创建圆对,检测它们的碰撞状态,并在每次用户按空格键时都会显示GDIDrawer窗口。如果用户按下任何其他键,即使在评估第一对之前,您的程序也将退出。 为了创建成对的圆圈,您将需要两组信息。每个圆将需要半径和由X和Y坐标对描述的中心点。这些值应随机生成,遵守以下规则: 1)每个半径的大小应在25到200之间。 2)圆圈的位置应设置为使得每个圆的整体可以显示在GDIDrawer窗口内。请记住,GDIDrawer窗口是800 x 600像素。 一旦生成了描述圆的值,就必须创建一个方程式,以便确定圆是否发生碰撞。要清楚的是,如果你的等式确定圆圈正在接触或重叠,那么它们将被认为是相撞的。 最后,如果你的等式确定圆圈已经碰撞,你应该显示两者GDIDrawer窗口中的红色圆圈,如下图顶部的图11-1所示。另一方面,如果你的等式确定圆圈没有碰撞,那么你应该在GDIDrawer窗口中显示红色,绿色和蓝色的随机值,如下页底部的图11-2所示。 图11-1:碰撞的圆圈样本集 图11-2:未碰撞的圆圈样本集A collision occurs when two objects overlap. That is to say they both occupy the same space, either in whole or in part. As this shall be our first collision exercise, we shall limit our efforts to detecting collisions between pairs of circles.You shall repeat the process of creating circle pairs, detecting their collision status, and displaying them in the GDIDrawer window each time the user presses the spacebar. If the user presses any other key, even before the first pair is evaluated, your program shall exit.In order to create pairs of circles you will require two sets of information. Each circle will require a radius and a center point described by an X- and Y-coordinate pair. These values shall be generated randomly, adhering to the following rules:1) Each radius shall have a size between 25 and 200 inclusive.2) The location of the circles shall be set such that the entirety of each circle may be displayed within the GDIDrawer window. Remember that the GDIDrawer window is 800 x 600 pixels.Once the values for describing the circles have been generated, you must create an equation which will allow you to determine whether the circles collide. To be clear, if your equation determines that the circles are either touching or overlapping, then they shall be considered to have collided.Finally, if your equation determines that the circles have collided, you shall display both circles colored red in the GDIDrawer window as shown in Figure 11-1 at the top of the following page. On the other hand, if your equation determines that the circles have not collided, then you shall display them in the GDIDrawer window with randomized values for red, green, and blue as shown in Figure 11-2 at the bottom of the following page.Figure 11-1: Sample Set of Circles Which Have CollidedFigure 11-2: Sample Set of Circles Which Have Not Collided推荐答案 这篇关于碰撞检测两个圆圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-31 10:36