47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
import numpy as np
|
||
import matplotlib.pyplot as plt
|
||
|
||
|
||
class SCurveGenerator:
|
||
def __init__(self, start, end):
|
||
self.start = start
|
||
self.end = end
|
||
self.current = start
|
||
self.t = np.linspace(0, 1, 100) # 用于生成S曲线的参数
|
||
self.index = 0
|
||
|
||
def generate_point(self):
|
||
if self.current >= self.end:
|
||
return None
|
||
# 修改后的S曲线公式,使中间部分陡峭,两边较慢
|
||
s_curve_value = self.start + (self.end - self.start) * (10 * self.t**3 - 15 * self.t**4 + 6 * self.t**5)
|
||
point = s_curve_value[self.index]
|
||
self.index += 1
|
||
self.current = self.start + (self.end - self.start) * (self.index / 100)
|
||
return point
|
||
|
||
# 初始化起点和终点
|
||
start = 25
|
||
end = 50
|
||
|
||
# 创建S曲线生成器
|
||
s_curve_generator = SCurveGenerator(start, end)
|
||
|
||
# 保存数据点的数组
|
||
data_points = []
|
||
|
||
# 外部周期调用生成数据点
|
||
while True:
|
||
point = s_curve_generator.generate_point()
|
||
if point is None:
|
||
break
|
||
data_points.append(point)
|
||
|
||
|
||
# 生成图表
|
||
plt.plot(data_points)
|
||
plt.title('S Curve')
|
||
plt.xlabel('Step')
|
||
plt.ylabel('Value')
|
||
plt.show()
|