views:

44

answers:

2

I need to move a ball in a circular path. Any guide or tutorials that I can refer to on how do I go about doing it? Thank you.

+2  A: 

In terms of co-ordinates x and y it would just be

x = x_c + r cos(theta)
y = y_c + r sin(theta)

where (x_c,y_c) is the centre of the circle and r is its radius. If your x-y system is one where the positive y direction is downwards then this would describe a clockwise path otherwise it's an anticlockwise path (as theta increases).

Edit

Just noticed you mentioned ellipses as well. If the ellipse is axis aligned then just use the major/minor radii instead eg.

x = x_c + a cos(theta)
y = y_c + b sin(theta)
Troubadour
A: 

Another way is to do this with Core Animation. Simply put the ball in a layer or view and make it move on a path. You can create the path with a series of bezier curves. You will have to understand a bunch of high level concepts but then the OS will take care of mostly everything involved.

St3fan