Creating a non built in shape

Hi all!
First: Thanks for this library. It's really simple easy to use (despite few strange things).
The problem is simple (I think) but I don't know the solution. I want to create a shape, which is a mix of two shapes: a circle and a box. I want to do something like w bumper:
Code:
    ____
  /      \
/         \
|          |
|__________|


The upper thing is a part of a circle. Itcan be connected to the box at different parts of the circle, so the chord length isn't constant.
How is it possible to create such a shape in Box2D?

Thanks for any help 🙂
I don't think it's possible in the general case (assuming I understand the type of configuration you have in mind).

If the circle is connected to the box along its midline, and if the box depth is >= the circle radius, you can just superimpose a circle and a box, but you probably already knew that.

Otherwise, I can't think of a way to do it. Box2D makes the following shapes available: polygons, circles, and (depending on the version) line segments in various forms. The shape you're describing can't be described exactly by any combination of these basic shapes, if I'm not mistaken, so you may have to look for alternatives. (Keep in mind that from an implementation standpoint, sticking with simple primitives such as circles, polygons, and segments is generally a wise choice, as it makes for more robust and efficient collision detection code. Supporting the type of shape you're describing natively would be more difficult.)

One alternative would be to use a single polygon, with the 'bump' approximated using line segments (keep in mind that the visual representation and the representation in the physics world don't necessary have to match exactly). You would want to use enough line segments to create a reasonable approximation of a curved surface, but not so many that you overload the collision detection system. (Note that you might have to adjust the 'max polygon vertices' setting to facilitate this.)
In practice, I have found polygons to work great for approximating curves.
Thanks for the answers 🙂 I'll figure something out now.
Hi.
I've found another problem. I try to create my own shape by using the line approximation. I calculated all the vertices and their coordinates are (the approximation of a circle with 3 point - a triangle):
Code:
0.76, 0.275
-0.76, 0.275
-0.76, 0.0
0.0, 0.275
0.76, 0.0


The problem is that the fourth point results in assertion (s<-b2_linearSlop). I think it has to be connected with wrong(?) normal calculation. This set of points gives the normals:
Code:
0.0, 1.0
-1.0, 0.0
0.34, -0.94
-0.34, 0.94
1.0, 0.0


The third and fourth x normal coordinate should be switched with each other. Why is it happening?

Thanks for any help 🙂
Double-check your coordinates - it looks to me like the polygon they form is non-convex.

Perhaps (0.0, 0.275) was supposed to be (0.0, -0.275)?
Thanks again 🙂 The problem was of course the y coordinate. THe order of one subtraction was wrong and this was causing a problem.

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