Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > moving object along circle

Reply
Thread Tools

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..
 
Reply With Quote
 
 
 
 
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
 
Reply With Quote
 
 
 
Reply

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Free Moving Estimate, Local Movers, Long Distance Moving, PackingSupplies, Storage Rental, Home Moving, Apartment Moving, Office Moving,Commercial Moving linkswanted ASP .Net 0 01-06-2008 04:45 AM
Moving along an angle Max Java 6 03-25-2007 12:28 AM
Jisatsu circle (Suicide Circle) Col's Cavern DVD Video 1 06-07-2004 06:55 PM
moving label in c# around circle =?Utf-8?B?dGFnaHJlZWQ=?= ASP .Net 1 05-03-2004 04:27 PM



Advertisments