import numpy as np
import matplotlib.pyplot as plt
def 二阶贝塞尔曲线模拟鼠标滑动轨迹(x0, y0, x1, y1):
# x0, y0 = 0, 0 # 起点
# x1, y1 = 100, 0 # 终点
span = abs(x0 - x1) if abs(x0 - x1) > abs(y0 - y1) else abs(y0 - y1)
P = np.array([span, span / 2])
P0, P1 = np.array([x0, y0]), np.array([x1, y1])
x, y = [], []
step = round(10 / span, 2)
for t in np.arange(0, 1.01, step):
p11_t = (1 - t) * P0 + t * P
p12_t = t * P1 + (1 - t) * P
p2_t = (1 - t) * p11_t + t * p12_t
x.append(round(p2_t[0]))
y.append(round(p2_t[1]))
print(round(p2_t[0]), round(p2_t[1])) # 可以直接加 moveto command
# plt.scatter(x, y, c='r', marker=".")
# plt.axis("equal")
# plt.show()
if __name__ == '__main__':
二阶贝塞尔曲线模拟鼠标滑动轨迹(0, 0, 111, 111)
python二阶贝塞尔曲线模拟鼠标滑动轨迹
最新推荐文章于 2024-05-13 09:45:24 发布