对于(x,y)像素的线长度坐标,将角度调整为圆形

问题描述 投票:0回答:1

我具有生成给定角度和像素长度的线的像素坐标的功能。

    # Start position of line
    lineStartX = 100
    lineStartY = 100

    # Length of line in pixels
    lineLength = 100

    # Set angle of line
    angle = 0

    for pixel in range(lineLength):

        # Next pixel with angle adjustment
        endy = (pixel + 1) * math.sin(math.radians(angle))
        endx = (pixel + 1) * math.cos(math.radians(angle))

        # Add next pixel with angle adjustment to line start coordinates
        Xcoordinate = lineStartX + (endx)
        Ycoordinate = lineStartY + (endy)

如何调整每个并发像素坐标形成一个圆的角度?

我已经尝试为每个像素递增地调整角度,但是它只是形成一个螺旋,我不确定下一步该怎么做。

        angle += 0.10

更新:当我按照建议增加角度时:

        angle += 2 * np.arcsin(math.pi / lineLength)

enter image description here

圈子仅部分完成

python coordinates pixel
1个回答
0
投票

如果线是圆,则长度等于其周长。由于不可能在像素矩阵上绘制完美的圆,因此将遵循一些近似规则。您可以尝试通过[>]而不是0.10逐步调整角度

2 * arcsin(pi / length)

使螺旋的末端相交:)

© www.soinside.com 2019 - 2024. All rights reserved.