0

我试图让这个随机生成的太阳系代码沿轨道弧随机显示“行星”。我正在努力在这里找到/使用正确的公式(参见图片以了解现在的样子)。

draw_orbit(cr, 4, width/2, sun_center, height - next_center - border_size, .6, .6, .6)是轨道弧的代码,为弧height - next_center - border_size的半径。

圆圈上的当前点数组......但公式是错误的,我似乎无法理解:

def points_on_circum(r,n=100):
     points_positive = []
     for x in range(0, n + 1):
         xcoord = (math.cos(2 * math.pi / n * x) * r)
         ycoord = (math.sin(2 * math.pi / n * x) * r)
         if xcoord > 0 and ycoord > 0:
             points_positive.append((xcoord, ycoord))
     return points_positive

目前关于如何获得随机 x, y 放置坐标的想法:

arc = height - next_center - border_size
placement = random.choice(points_on_circum(arc))
         
draw_circle_fill(cr, placement[0],placement[1], next_size, r, g, b)

轨道功能:

def draw_orbit(cr, line, x, y, radius, r, g, b):
    cr.set_line_width(line)
    cr.arc(x, y, radius, 0, 2*math.pi)
    cr.stroke()

我正在尝试沿弧线随机生成行星,但目前它们都在同一位置:

在此处输入图像描述

4

0 回答 0