Python 如何使椭圆形与20条直线重复?

Python 如何使椭圆形与20条直线重复?,python,algorithm,Python,Algorithm,我需要为一个补丁程序创建此形状,该程序以特定模式重复补丁。我不知道从哪里开始创建这个,因为它只使用了20条直线,所以任何帮助都会很棒 这将为您提供一组要绘制的线: from dataclasses import dataclass @dataclass class Point: x: int y: int @dataclass class Line: p1: Point p2: Point def lower_left_mesh(height, width,

我需要为一个补丁程序创建此形状,该程序以特定模式重复补丁。我不知道从哪里开始创建这个,因为它只使用了20条直线,所以任何帮助都会很棒


这将为您提供一组要绘制的线:

from dataclasses import dataclass

@dataclass
class Point:
    x: int
    y: int

@dataclass
class Line:
    p1: Point
    p2: Point

def lower_left_mesh(height, width, n):
    return [
        Line(
            Point(0, i * (height - 1) // n),
            Point((i + 1) * (width - 1) // n, height - 1)
        )
        for i in range(n)
    ]
例如:

>>> lower_left_mesh(101, 101, 10)

[Line(p1=Point(x=0, y=0),  p2=Point(x=10, y=100)),
 Line(p1=Point(x=0, y=10), p2=Point(x=20, y=100)),
 Line(p1=Point(x=0, y=20), p2=Point(x=30, y=100)),
 Line(p1=Point(x=0, y=30), p2=Point(x=40, y=100)),
 Line(p1=Point(x=0, y=40), p2=Point(x=50, y=100)),
 Line(p1=Point(x=0, y=50), p2=Point(x=60, y=100)),
 Line(p1=Point(x=0, y=60), p2=Point(x=70, y=100)),
 Line(p1=Point(x=0, y=70), p2=Point(x=80, y=100)),
 Line(p1=Point(x=0, y=80), p2=Point(x=90, y=100)),
 Line(p1=Point(x=0, y=90), p2=Point(x=100, y=100))]

这实际上是一个数学系列。只要看看直线的起点和终点,以及它们是如何增加和减少的,你就能找到一个解决方案

s = 1000
img = np.full((s,s,3), 255, dtype='uint8')
inc = 10

color = [0,0,255]
for i,j in zip(range(0,s+1,inc), range(0,s+1,inc)):
    cv2.line(img, (i,1), (s,i), color, 2)
    cv2.line(img, (1,j), (j,s), color, 2)

cv2.imshow('img', img)
cv2.waitKey(0)

仔细查看线段的坐标。。。