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:

    radius = 100
    from math import sqrt
    for x in range(-radius,radius):
    y = sqrt(radius**2-x**2)
    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
    #1
    1. Advertising

  2. 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:
    >
    > radius = 100
    > from math import sqrt
    > for x in range(-radius,radius):
    > y = sqrt(radius**2-x**2)
    > 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
    radius = 100
    for angle in range(0, 361):
    theta = math.radians(angle)
    x = radius*math.cos(theta)
    y = radius*math.sin(theta)
    print(x, y)



    --
    Steven
    Steven D'Aprano, Nov 21, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?dGFnaHJlZWQ=?=

    moving label in c# around circle

    =?Utf-8?B?dGFnaHJlZWQ=?=, May 2, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,781
    clintonG
    May 3, 2004
  2. Max

    Moving along an angle

    Max, Mar 23, 2007, in forum: Java
    Replies:
    6
    Views:
    386
    Jeff Higgins
    Mar 25, 2007
  3. linkswanted
    Replies:
    0
    Views:
    672
    linkswanted
    Dec 21, 2007
  4. linkswanted
    Replies:
    0
    Views:
    1,535
    linkswanted
    Jan 6, 2008
  5. linkswanted
    Replies:
    0
    Views:
    435
    linkswanted
    Jan 23, 2008
Loading...

Share This Page