简体   繁体   English

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

[英]For (x, y) pixel coordinates in length of line, adjust angle to become circle

I have have a function to generate pixel coordinates of a line of a given angle and pixel length.我有一个 function 来生成给定角度和像素长度的线的像素坐标。

    # 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)

How can i adjust the angle of each concurrent pixel coordinate to form a circle?如何调整每个并发像素坐标的角度以形成一个圆圈?

I've tried adjusting the angle incrementally for each pixel but it only partially completes the circle, I'm not sure what to do next.我已经尝试逐步调整每个像素的角度,但它只是部分完成了圆圈,我不确定下一步该怎么做。

        angle += 0.10

Update: When i increment the angle as suggested:更新:当我按照建议增加角度时:

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

在此处输入图像描述

The circle still only partially completes圈子还只是部分完成

Should the line be a circle, the length equal would its circumference.如果这条线是一个圆,长度等于它的周长。 Since drawing a perfect circle on a pixel matrix is not possible, some approximation rules will be in order.由于不可能在像素矩阵上绘制一个完美的圆,因此需要一些近似规则。 You could try incrementally adjusting the angle not by 0.10 but by您可以尝试增量调整角度,而不是 0.10,而是

2 * arcsin(pi / length)

to make the spiral's ends meet:)使螺旋的收支平衡:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM