IPhone Drawing Question

Discussion in 'iPhone/iPad Programming' started by ravi124, Mar 4, 2009.

  1. macrumors newbie

    Joined:
    Mar 4, 2009
    #1
    I am new to iphone sdk development.

    I created a circle with CGContextAddEllipseInRect() and It is working fine.
    I have some other view (ball) which I want to move inside the circle randomly (Random moving I did already).
    What I want is , If Ball view touches the circle line it has to move back.

    How can I know the whether the ball touches the circle line or not ?

    I searched a lot on the net but no luck ?

    Thank You,
    Ravi,
     
  2. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #2
    If the two objects are perfect circles it's easy. You know the two radii and you can work out the distance between the two centers using basic trigonometry. You will then know the distance of the furthest edge of the ball from the origin of the circle. When this distance is the same as the circle's radius they're touching.
     

Share This Page