Sign up ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've been using box2D for a few months, but I now badly need a physics library which can use boolean shapes (ie; cutting a circle out of a square) and/or curved surfaces. Does anyone have any suggestions?

Edit: Language is c++

share|improve this question
Language you're using? – The Communist Duck Aug 2 '11 at 17:00
Sorry, C++ and I don't mind something written in C or another language with C bindings – deek0146 Aug 2 '11 at 17:05
@deek0416: C compatibility is part of C++- if you run C++ you don't need to tag C. – DeadMG Aug 3 '11 at 21:18
DeadMG: I didn't actually tag C, I was just saying I don't mind a C style library, or more importantly, a library written in another language which has C bindings – deek0146 Aug 5 '11 at 16:11

3 Answers 3

Have you considered combining standard box2d shapes/fixtures and convex polygon attaching them to same body?

If you want you can even implement concave decomposition algorithms like the ones provided by this .NET(C#) Box2d port (at the bottom, it also supports some boolean operations):

PS: there should be some performance/complexity reason(s) for not supporting concave polygons as is.

share|improve this answer
Polygon processing algorithms are heavily iterative, thus each step of the algorithm needs to be kept as lightweight as possible. Concave, self-intersecting and holed polygons present many edge cases, and require processing that is orders of magnitude greater than processing convex polygons. The combination of edge cases can make for further, even more specialised edge cases to watch out for. Concave vs convex is a common problem in developing physics, geometric and geospatial libraries. The tradeoff? Fast processing of many bodies vs a more flexible interface for polygon construction. – Arcane Engineer Aug 5 '11 at 10:15

I'm not sure there's such a thing as what you're describing. Everything is/can be made out of convex shapes, especially in graphics/physics math (this makes operating on bodies much easier)

It's more about finding, making, and implementing algorithms that break complex shapes down into as few simple shapes as possible. This is called Polygon Partitioning, and to do this i would suggest this simple, nearly includable library:

Physics math can much more accurately work with curved items such as circles though, as there are very quick equations when shapes have a common radius. I would suggest simply putting circles (or only a section of a cirlce) and polygons together to form whatever curved, pointy, or other crazy shapes you want to make. And again there are most likely algorithms for this out there even now.

you can also put "holes" into shapes by adding a "hole" shape to a body, and then test at run time whether a colliding shape is inside the whole or not. Then don't do any collision if it is.

also if you didn't know; sine and cos waves are very helpful for making curved hills and such.

share|improve this answer

I now badly need a physics library which can use boolean shapes (ie; cutting a circle out of a square) and/or curved surfaces

The term you are looking for is

  • (2D) CPG -- constructive planar geometry
  • (3D) CSG -- constructive solid geometry

If you can live without curves (at least in your cut-out areas), go for the approach @Den suggests.

If you need to be able to slice polygons along curves, you are pretty much going to have to find a CSG library such as GPC. And you are going to have to be able to find one that supports splines in its intersections. And then you are going to have to transport that spline data into Box2D. And be warned -- good CPG libraries cost several hundred to several thousand dollars. There are free ones out there but they are by no means as full featured or as well optimised (in general, though they are not intended for real time use).

One thing I will warn you on -- if you don't have at minimum a graduate level background in mathematics, do not attempt a custom solution to the polygon intersection problem at home. There is a reason they charge big bucks for these solutions.

share|improve this answer
Anonymous downvoter strikes again. Someone's abusing the system nicely! – Arcane Engineer Aug 6 '11 at 21:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.