moving object along circle

S

sparx10

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..
 
S

Steven D'Aprano

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)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top