Velocity Reviews > moving object along circle

# moving object along circle

sparx10@gmail.com
Guest
Posts: n/a

 11-21-2012
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..

Steven D'Aprano
Guest
Posts: n/a

 11-21-2012
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/mat...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

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post linkswanted ASP .Net 0 01-06-2008 04:45 AM Max Java 6 03-25-2007 12:28 AM Col's Cavern DVD Video 1 06-07-2004 06:55 PM =?Utf-8?B?dGFnaHJlZWQ=?= ASP .Net 1 05-03-2004 04:27 PM

Advertisments