# moving object along circle

Discussion in 'Python' started by sparx10@gmail.com, Nov 21, 2012.

1. ### Guest

I'm trying to move an object along a circle (orbit), and I did come up withthis:

from math import sqrt
print(x, y)

however it moves faster at the beginning and end of the range (y value changes faster than x value) because the x value is changing at a constant ratebut the y value isn't. I can't think of a way to get something to move smoothly around in a circle though..

, Nov 21, 2012

2. ### Steven D'ApranoGuest

On Tue, 20 Nov 2012 19:35:00 -0800, sparx10 wrote:

> I'm trying to move an object along a circle (orbit), and I did come up
> with this:
>
> from math import sqrt
> print(x, y)
>
> however it moves faster at the beginning and end of the range (y value
> changes faster than x value) because the x value is changing at a
> constant rate but the y value isn't. I can't think of a way to get
> something to move smoothly around in a circle though..

Instead of using rectangular (x, y) coordinates directly, use polar
coordinates (r, Î¸) where r (radius) is the constant radius of your
circle, and Î¸ (theta) smoothly varies between 0 and 360Â°.

http://www.teacherschoice.com.au/maths_library/coordinates/polar_-_rectangular_conversion.htm

import math
for angle in range(0, 361):
print(x, y)

--
Steven

Steven D'Aprano, Nov 21, 2012