Search code examples
iphonecore-graphicsquartz-graphics

Overlaid images


I'm creating an application where I will be drawing two circles onto the screen, one large circle with a smaller circle inside. I want the user to be able to touch/drag on the screen inside or outside of the large circle and it will move the smaller circle in that direction. If the user touches outside of the large circle the smaller circle will not go outside of the larger circle's border.

With the research I've done I can easily draw the two circles inside of each other and handle the movement of the smaller image. However, I don't see an easy way to limit the smaller circle to stay inside of the larger circle. All I have found is clipping but that would just cause the smaller circle to only be partially drawn. Does anyone have a good point of reference I could use to start looking into how this is possible? Thanks.


Solution

  • Lets say the big circle has Radio Rb and Center Cb. The inner circle would be Ri and center Ci.
    If you set the distance from Ci to Cb ( from the inner circle center to the center of the big one) to be less than Rb-Ri ( than the rest of the big radious from the inner radious) you'll always have the inner circle inside.. Do you get the idea? Just draw it and see that it always is true) Distance (Ci to Cb) < Rb-Ri The only thing you need to do is check for this to be true.

    Distance from Ci to Cb is Math.Sqrt( math.Pow(Cix-Cbx,2)+Math.Pow(Ciy-Cby,2))