How can i make a smooth circular orbit at a constant speed using pygame? How would i calculate x, y on a circle?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Rotating about the 2d point center
with the given radius and speed.
The parameter t
is the time in units of seconds.
def circular_orbit(center, radius, speed, t):
theta = math.fmod(t * speed, math.PI * 2)
c = math.cos(theta)
s = math.sin(theta)
return center[0] + radius * c, center[1] + radius * s
回答2:
Try using polar coordinates. It's natural :)
If you don't calculate enough frames to make your orbit look smooth, calculate 3-4 intermediate points of orbit to draw shorter line segments, without calculating the game state at these points. Make this radius-dependent. This helps proper collision detection, too.