目录
pingyi2.py
pingyi2.py
import numpy as np
import cv2
# 画线段的函数
def draw_line(img, p1, p2, color, thickness=2):
cv2.line(img, tuple(p1), tuple(p2), color, thickness)
# 创建图像并初始化
def create_image():
# 创建一个黑色背景图像
img = np.zeros((500, 500, 3), dtype=np.uint8)
return img
# 线段平移的函数
def translate_line_a_along_b(img, a_start, a_end, b_start, b_end, steps=50):
# 计算b线段的方向向量
b_vector = np.array(b_end) - np.array(b_start)
b_length = np.linalg.norm(b_vector)
b_unit_vector = b_vector / b_length # 单位向量
# 设置平移的步长
step_siz