Checking if a circle is within a polygon

Hi everyone,

I'm making an iPad game using box2d.
In the game, you drag disks with your finger inside a polygon shape.

To make the disk you selected follow your finger but still have physics react properly, I'm setting a velocity for the disk toward the finger position.
However, my problem is that if you touch outside the wall boundaries of the polygon shape representing walls, the disk keeps smashing in the walls infinitely.

To stop this, I want to simply not draw the disk if the position I touch would have caused the disk position on it to be outside the polygon shape or overlap it.

Is there a simple way to do it via the box2d api?
My other option is to calculate this mathematically, but I'm trying to avoid that since I'm sure box2d knows how to calculate these things.

Note that the polygon edges are static and never change, and that I want to know basically if the disk (a circle) is completely within the polygon based on the center position and its radius.

I've tried create a demi-body and checking for collision via the b2ContactListener interface, but the problem is that I want to know immidiately if this is the case and the listener is being called only after my function is done, and a Step is being run...

Thanks!
Idan
Kinda tricky huh. How about if you kept the position of the body one step behind the finger...
For example, you could have a second body with an identical fixture that follows the touch exactly as the real body does now, but with an invisible sensor. Each step you could check if this sensor had touched the edge, and if not then set the target position of the real body to the previous position of the sensor.
It's a good idea and might work, but before trying it I've managed to solve it by defining a polygon shape, then creating a circle shape on the fly with the same size as the disk and a transform to where the finger is, and simply using TestPoint on the polygon shape and b2TestOverlap to find out weather the circle shape is completely inside the polygon (its center is within the polygon and the disk shape doesn't overlap with any of the polygon edges).

This solved it nicely and I'm glad I found a box2d way to do it 🙂

Thanks!
Idan

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