'Calculate the angle between two points over a period of time
I would like to calculate the angle between two points in a coordinate system over a period of time.
X: Time Y: Values of a currency Pair.
For example:
At 10AM(X1) the pair was at 1.1110(Y1) Euros. At 11AM(X2) the pair was at 1.1190(Y2) Euros.
Now I would like to calculate the angle. Do I need to calculate the DeltaX like: Delta 1 hour = 60 min = DeltaX = 60?
Or do I need to convert the time to something else?
I tried it like this already but the outcome seems to be not right.
x1 = 0
x2 = 60
y1 = 1.1110
y2 = 1.1190
delta_y = ((y2)-(y1))**2
delta_x = ((x2)-(x1))**2
radian = math.atan2(delta_y, delta_x)
degree = radian*(180/math.pi)
print(degree)
Outcome: 0.0002291831180511074
Solution 1:[1]
I think the following should work and convert your values into the right angle in degree:
import math
x1 = 0
x2 = 60
y1 = 1.1110
y2 = 1.1190
#Calculate the length of the opposite and adjacent sides
delta_y = y2 - y1
delta_x = x2 - x1
# Calculate tangens
tan = delta_y / delta_x
# Calculate inverse function of tangens (arctan)
alpha_rad = math.atan(tan)
#Calculate alpha from rad to degree
alpha_degree = alpha_rad * (180/math.pi)
print(alpha_degree)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DonFlo |
