Python给定半径和中心的圆上的所有点

2024-09-27 04:27:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我写了这个函数:

def get_x_y_co(circles):
    xc = circles[0] #x-co of circle (center)
    yc = circles[1] #y-co of circle (center)
    r = circles[2] #radius of circle
    arr=[]
    for i in range(360):
        y = yc + r*math.cos(i)
        x = xc+ r*math.cos(i)
        x=int(x)
        y=int(y)
        #Create array with all the x-co and y-co of the circle
        arr.append([x,y])
    return arr

“circles”是一个数组,[X-center, Y-center, Radius]

我想提取圆中存在整数分辨率的所有点。 现在,我意识到我正在创建一个位于圆边界上的点数组,但是我无法访问圆内的点。

我只想减小半径,并对半径的所有值进行迭代,直到半径为0

但我觉得有一个更有效的方法。欢迎任何帮助


Tags: ofthe函数半径math数组cosint

热门问题