I have a graph of discrete set of points.
y x
0 1.000000 1000.000000
1 0.999415 1000.000287
2 0.999420 1000.000358
3 0.999376 1000.000609
4 0.999239 1000.000788
5 0.999011 1000.000967
6 1.000389 1000.001433
7 0.999871 1000.001756
8 0.995070 1000.002723
9 0.996683 1000.003404
I want to determine the longest chain of consecutive points where the slope of the line connecting i-1
to i
remains within a given range epsilon = 0.4
.
def tangent(df, pt1, pt2):
y = df.iloc[pt2]['y'] - df.iloc[pt1]['y']
x = df.iloc[pt2]['x'] - df.iloc[pt1]['x']
return x/y
The data has been normalized to scale the tangent results.
index = 1
while index < df.shape[0]:
if abs(math.tan(tangent(df,index-1,index) * math.pi)) < epsilon:
print("result:",index)
index += 1
The snippet is the draft to detect all such points.