I am working on a problem in iOS that involves a moving circle (circle a of radius r) within a larger static circle (circle b of radius t). t > r.
Circle a can move anywhere within circle b, but stops as soon as it touches circle b. I'm implementing the rendering of the circle by adding x and y offsets to the starting center point of circle a, and redrawing it each time. The calculations for the offsets are being made using some gravity and friction coefficient values. I understand that I have to subtract some value from the offsets if circle a goes out of circle b. How do I calculate the offsets in a way that circle a is constrained within circle b?
I can achieve the same when constrained in a rectangle, but scratching my head making the calculations for constraining it in a circle.
Any help is greatly appreciated.