I'm trying to determine angle in degrees of a straight line of two points, I came across many solutions online but none of them worked for me, consider this piece of code
import matplotlib.pyplot as plt
data = np.array([7405.,7447.4,7433.99,7410.,7443.15,7429.4,7590.03,7550.,7566.32,7619.62,7549.71,7551.8,7530,7522.99,7499.75,7453.99,7542.16,7564.,7552.77,7552])
y = [7606.672474,7570.240928]
plt.plot(data)
plt.plot([6,17], y)
plt.show()
The target line is y
it should be around -5 degrees just by looking at it.
It seems like most online solutions suggest that we can find the angle by doing
degree = np.math.atan2(y[-1] - y[0], x[-1] - x[0])
degree = np.degrees(degree)
I omitted the other values of y to just the first and last point for simplicity so the x[-1] - x[0]
part here would be 11=17-6 which is the length of y line across the x-axis, this is what most online solutions suggest, however all the approaches failed to get the right angle for this, I should note that during my tests some approaches seemed to give the right angle for a given data unit for example while totally failing on a different data unit like
data = [52.3384984,53.04757978,52.04276249,51.77348257,49.93056673,52.24062341,55.74022485,60.77761392,60.89290148,60.1995072,60.40524964,59.00590344,59.67589831,56.49266698,49.02464746,51.53876823,57.77368203,59.48092106,56.63155446,56.0648491 ]
y = [51.337288,50.331895]
plt.plot(data)
plt.plot([3,15], y)
plt.show()
I also tried to min-max normalize the data but no success, so considering we have the first and last point of a line and its length how can we or is it possible to determine its angle in degrees?