One-vertex shape ?

Hi,

I would like to attach a sensor to a body, that represents a point of the body (the center, for example).
Is there a way to do so ? I tried to use b2PolygonDef with 1 vertex, but it does not seem to be suitable.

Thanks.
I doubt a one-vertex polygon will work. You can always check the source code to make sure, but commonly used algorithms for raytracing and detecting intersections between polytopes typically assume that the polytope is bounded by n hyperplanes. I know that (as of fairly recently, at least), the polygon raytrace function does not consider the special case of a one-vertex polygon (which would be kind of nonsensical anyway), and I doubt that the other polygon-related functions do either. Again though, you can always look at the code if you're curious.

I think the most obvious solution here would be a circle with a small radius. I'm not sure what the implications would be of using a circle with a radius of zero or with very small magnitude - maybe someone else can comment on that.
I tried the 1-vertex polygon and it definitely does not work. The engine is nicely protected against that:

Code:
Source/Collision/Shapes/b2PolygonShape.cpp:147: b2PolygonShape::b2PolygonShape(const b2ShapeDef*): Assertion `3 <= m_vertexCount && m_vertexCount <= b2_maxPolygonVertices' failed.


How do you guys do, when you need to decide in which zone of the partitioned world an object is ? This feels like a common need to me, and I'm not comfortable with using a small enough circle (or other small shape): there will always be cases where the shape overlaps several zones. Besides, can really small shapes do singular-like things to the simulation ?

Thanks.
Lacking a better solution, I tried creating a very small shape, and got some error:
Code:
Source/Collision/Shapes/b2PolygonShape.cpp:224: b2PolygonShape::b2PolygonShape(const b2ShapeDef*): Assertion `d.x >= 0.0f' failed.

This occurs for example with:
Code:
shapeDef2.SetAsBox(0.03f, 0.03f);

It's working OK with:
Code:
shapeDef2.SetAsBox(0.04f, 0.04f);

but this looks big to me, and strangely not corresponding to the assert text (unless floating calculations are really less precise than I expected). I could not find the code (I'm running on version 2.0.1), but can't say I searched very seriously.
Try upgrading to 2.1 then. I think a most of that stuff was removed.
A circle with zero radius might work. I haven't tried it. You can also use b2World::QueryAABB and TestPoint on the fixtures. This is how the mouse joint works in the testbed.
A circle with 0 radius seems to work fine, thanks for the tip !
I first decided to go for a polygon, imagining it was more efficient, and then couldn't think outside the box 🙂

Edit: sorry I was wrong (can't code properly): it does not work either, but the accepted limit is much smaller with a circle (somewhere around 0.0000153f radius).

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