一个圆反射另一个圆

发布于 2024-09-08 09:14:10 字数 400 浏览 8 评论 0原文

使用 iPhone 和 Objective C。

我正在开发一款游戏,我需要正确反射圆形物体上的球。我试图将其作为直线和圆的交点来完成。我的球位置位于圆圈之外,而新的球位置将在下次抽奖更新时位于圆圈内部。我知道直线(球路径)和圆的交点。现在我想围绕交点旋转球路径的终点,以获得切线的正确反射角度。

以下是已知的:

  • 球当前 x,y
  • 球端 x,y
  • 球半径
  • 圆心 x,y
  • 圆半径
  • 球路径与圆 x 和 y 的交点

我知道我需要找到切线和圆之间的入射角来球路径也将等于我的反射角。我想一旦我知道了这两个角度,我就可以用 180 度减去它们来得到我的旋转角度,然后将我的端点围绕相交角度旋转这个量。我只是不知道怎么办。

Working with iPhone and Objective C.

I am working on a game and I need to correctly reflect a ball off a circle object. I am trying to do it as a line and circle intersection. I have my ball position outside the circle and I have the new ball position that would be inside the circle at the next draw update. I know the intersect point of the line (ball path) and the circle. Now I want to rotate the ending point of the ball path about the intersection point to get the correct angle of reflection off the tangent.

The following are known:

  • ball current x,y
  • ball end x,y
  • ball radius
  • circle center x,y
  • circle radius
  • intersection point of ball path and circle x and y

I know I need to find the angle of incidence between the tangent line and the incoming ball path which will also equal my angle of reflection. I think once I know those two angles I can subtract them from 180 to get my rotation angle then rotate my end point about the angle of intersection by that amount. I just don't know how.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

明明#如月 2024-09-15 09:14:11

首先,您应该注意,球的中心不必位于圆圈内才能表明存在反射或弹跳。只要球心与圆的距离小于球的半径,就会发生弹跳。

如果圆的半径为R,球的半径为r,如果转换为圆的半径为R+的情况,事情就会变得简单r 且球的半径为 0。出于碰撞检测和反射/弹跳的目的,这是等效的。

如果您有(放大的)圆和球路径之间的交点,您可以轻松计算该点处圆的法线N(它是从中心方向的单位向量)圆到碰撞点的距离)。

对于传入向量 V,反射向量为 V-2(NV) N< /strong>,其中 (NV) 是点积。对于这个问题,输入向量V是从交点到圆内点的向量。

至于上面给出的反射公式,使用向量数学推导相对容易,但您也可以 Google 搜索“计算反射矢量"。公式中的符号将随VN的假设方向而变化。 Mathworld 有一个推导,尽管如前所述,符号不同。

First, you should note that the center of the ball doesn't have to be inside of the circle to indicate that there's a reflection or bounce. As long as the distance between ball center and circle is less than the radius of the ball, there will be a bounce.

If the radius of the circle is R and the radius of the ball is r, things are simplified if you convert to the case where the circle has radius R+r and the ball has radius 0. For the purposes of collision detection and reflection/bouncing, this is equivalent.

If you have the point of intersection between the (enlarged) circle and the ball's path, you can easily compute the normal N to the circle at that point (it is the unit vector in the direction from the center of the circle to the collision point).

For an incoming vector V the reflected vector is V-2(NV) N, where (NV) is the dot product. For this problem, the incoming vector V is the vector from the intersection point to the point inside the circle.

As for the reflection formula given above, it is relatively easy to derive using vector math, but you can also Google search terms like "calculate reflection vector". The signs in the formula will vary with the assumed directions of V and N. Mathworld has a derivation although, as noted, the signs are different.

柠檬心 2024-09-15 09:14:11

我只知道几何部分的解法。
让:
r1 =>球半径
r2 =>圆的半径

您可以使用毕达哥拉斯定理计算两个圆之间的距离。
如果距离小于r1+r2,则进行碰撞。

对于碰撞,我建议您这里。它是用 python 编写的,但我认为它应该让你知道该怎么做。希望甚至可以在 Objective C 中实现它。 PeterCollingRidge 的教程。

I only know the solution to the geometry part.
Let:
r1 => Radius of ball
r2 => Radius of circle

You can calculate the distance between the two circles by using Pythagoras theorem.
If the distance is less than the r1+r2 then do the collision.

For the collision,I would refer you Here. It's in python but I think it should give you an idea of what to do. Hopefully, even implement it in Objective C. The Tutorial By PeterCollingRidge.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文