获取形状相交的中心(2D)
我正在使用 Slick java 游戏库,并且使用了 形状 作为碰撞的碰撞箱,效果很好。我使用 shape1.intersects(shape2) 来检查两个形状是否重叠。现在我想做的是获取相交形状的中心点,用作生成显示两个对象之间碰撞的粒子的位置。
我找不到任何计算形状交叉的算法的解释,也许是因为我不知道它是否有特定的名称。
I'm using the Slick java game lib and I've used the Slick implementation of Shape as a hit-box for collision and that's working fine. I use shape1.intersects(shape2)
for checking if two shapes overlap. Now what I want to do is get the center point of the intersecting shape to use as a place to generate particles showing the collision between the 2 objects.
I can't find any explanations of algorithms that calculate shape intersections, maybe because I don't know if it has a specific name or not.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看文档,似乎有两种方法 -
union
和subtract
- 使用它们可以获得交集,如下所示:唯一的问题是这些方法似乎返回形状数组而不是单个形状,无论这意味着什么。
当然,实时执行此操作可能会非常昂贵,因此您也可以将碰撞点近似位于两个形状的边界框/圆的中心之间。
Looking at the documentation, there seem to be two methods --
union
andsubtract
-- using which you can get the intersection as follows:The only problem is that those methods seem to return an array of shapes instead of a single shape, whatever that means.
Of course, doing this in real-time could be quite costly, so you could alternatively approximate the collision point to be in between the centres of the bounding box/circle of the two shapes.