New Primitives - b2ConcaveArcShape & b2ConvexArcShape

b2ConcaveArcShape & b2ConvexArcShape Primitives

Originally this was just a small demo, but now I've produced a version of box2dFlash 1.4.3 which includes two new primitives - b2ConcaveArcShape & b2ConvexArcShape. They are not fully implemented but should work well in static objects. Between these and polygons, it is possible to represent any combination of intersections and unions of polygons and circles.

See a demo here:
http://boristhebrave.com/permajunk08/ConcaveArc.html

USAGE
Diagrams to come...
b2ConcaveArcShape
This shape can represent any polygon with a circle subtracted from it. It works exactly the same as b2PolyShape, except the edge from vertex 0 to vertex 1 is a concave arc, with radius given by the radius property. The diameter should be longer than the distance between the vertices, and the rest of the polygonal shape should be large enough to enclose the resulting curve (this is not checked).

b2ConvexArcShape
This shape is intended to represent any circle intersected with a half plane. The circle is as it would be for a b2CircleShape, i.e. centered at localPosition and of radius radius. The half plane is represented by norm, giving the outward normal, and offset, which is the offset of the halfplane's edge from the center of the circle. A zero offset means a semi-circle, with a positive offset being larger than that and a negative one smaller. Note: At the moment, only non-positive offsets are supported. localRotation can be used instead of norm.


Note that not all collisions are supported, specifically the arc shapes cannot collide with each other. This means you will have to structure your worlds such that this never needs to happen, probably by ensuring they are all static.

Future work & bugs:
  • Check that warm starting is working properly for both shapes.
  • Support a positive offset for b2ConvexArcDef
  • Implement collisions between convex arcs and another arc.
  • Possible port to C++? I have vaguely planned the extra code required for the upgrade to 2.0, but I would be keen on getting some help on board for the rest of the port. My C++ probably isn't up to scratch for making some of the design choices.
There's no guarantee I'll do any of this, I'm pretty bad at dropping projects. But hey, at least it's usable.


Latest source available here:
Wow that's really cool Boris,

I'd be interested in seeing this extended to support the other contacts, if it's not too much trouble.

If Erin is interested, I'd be happy to port the code back to c++, provided moving the code to 2.0 isn't too hard.
This is amazing! I would love to see this integrated into 2.0. Especially if this runs faster than having tons of polygons to simulate curved surfaces, which I imagine it does 😀
Woo, polygon support done. Now I just have to detect collisions between two arcs and I'm done.
See http://boristhebrave.com/permajunk08/ConcaveArc.html

Skatehead: You might have some difficulty porting back to C++. I've kept the coding conventions and such like as much as I can, but I've been lazy in a few places. Specifically, I use dictionaries to do contact matching (Box2D should really do this too), and a variable sized array for returning manifolds. Unlike the previous collision types, there can be an arbitrarily large number of manifolds (points of contact) between a polygon and a concave arc.

Brainclog: Though my code is not massively optimized, I should imagine it's miles faster than using polygons to approximate it. Particularly as it is a concave curve, so you need many separate polygons to approximate a smooth curve. And it is more accurate: stored normal forces won't get reset as often, and there are circumstances when the approximation breaks down. E.g. the "Zero-G" scenario, where rolling a circle around the perimeter of the playarea causes it to lose energy a lot slower than with an approximation.
Wow, that's really coming along well. This would open up so many doors for games. Especially for use in environments I think almost any game could benefit from a few concave arcs.
BorisTheBrave, your'e doing a great job, could you share the sourcefiles of your hack? It would be really usefull, as i'm currently working on a pinball game, which uses a lot of (both concave and convex) arcs and circle/arc collisions. I would really appreciate this, event without all possible collisions.

thanks 🙂
I do intend to eventually release the source, but I would really like to release the thing as a whole, so I can be sure it works ok. e.g. I had to write a lot of the poly-arc collision code after realizing that though the demo worked pretty well, it would behave terribly for more extreme sorts of shapes.
Ok, the last few messages prompted me to get of my arse and work on this.

I've now finished off arc-circle and arc-poly collisions to a satisfactory level, though I'm sure there are still bugs. However, arc-arc collisions are not done (and the problem looks pretty hard, so I might never do it), so stick to using them as static objects for now.

Usage:
There are a few example b2ConcaveArcDef's in the testbed provided, but I'll describe here how to create an arc.
Basically, b2ConcaveArcDef works the same as b2PolyDef, except you also provide a radius parameter. The shape created is the same poly you would get from the same vertices, except the line from vertex 0 to vertex 1 has been replaced with a concave curve with radius specified. The bounding polygon still needs to be convex. You cannot have a diameter shorter than the distance between these vertices, and you should not have a bounding polygon smaller than the arc it is enclosing. This is not checked for.

Note that using this way of defining shapes, you cannot get an arc of larger than pi radians (180 degrees). If you want larger you need compound shapes. Similarly, you need compound shapes to have multiple curves on one polygon. If you want the resulting shape from subtracting a circle from a polygon, you will need to write the code yourself, sorry. I'd be interested if you did, though.


Does anyone know how the licensing works? It's clear that I'm allowed to modify and redistribute the source, but how am I meant to make some changes indicating I've done so?

Let me know of any problems, I'll endeavor to fix them.

EDIT: Get the latest source from the original post.
thank you so much.
If I understand the problem right, I would think that arc-arc collisions should be very simple, actually - the only way these things can touch is if one touches the convex hull of the other, which is just a simple polygon, right? In particular, only a corner can touch the actual curved piece.

Original thread: https://box2d.org/forum/viewtopic.php?t=267