计算两点之间的插值点,简单的线性插值

"""计算两点之间的插值点,简单的线性插值"""

import math

def insert_point(a,b,step):
    """a:起点坐标二元组,b:终点坐标二元组,step:步长"""
    points = []
    x1,y1 = a       # 起点
    x2,y2 = b       # 终点
    dy = y2 - y1
    dx = x2 - x1
    angle = math.atan2(dy,dx)
    distance = int(math.sqrt(dx*dx+dy*dy))
    for d in range(1,distance,step):
        dx = d * math.cos(angle)
        dy = d * math.sin(angle)
        p = int(a[0] + dx),int(a[1] + dy)
        points.append(p)
    return points

start = (100,0)
end = (101,353)
p = insert_point(start,end,10)
print(p)