开发者

Get center of Shape intersection (2D)

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 ch开发者_如何学JAVAecking 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.


Looking at the documentation, there seem to be two methods -- union and subtract -- using which you can get the intersection as follows:

A ∩ B  =  A ∪ B - (A - B) - (B - A)

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜