I am trying to find the angle between two circle co-ordinates. These circle co-ordinates have been converted from 24 hours time data.
The issue is that when I calculated the angle between time 22:00 and 22:05, it is showing as 60 degrees, which is bizarre as there is only 5 minute difference between the two time, so it should not show 60 degrees as the angle.
import pandas as pd
import numpy as np
import math
df = pd.DataFrame(index=pd.date_range(start='6/1/2020', end='6/2/2020', freq='min')[:-1])
# integer array from 0 to 1439 (= 24 hours x 60 minutes)
df["x"]=np.linspace(0,24*60-1,24*60, dtype=int)
# We normalize x values to match with the 0-2π cycle
df["x_norm"] = 2 * math.pi * df["x"] / df["x"].max()
df["sin_x"] = np.sin(df["x_norm"])
df["cos_x"] = np.cos(df["x_norm"])
//p1 is the value for coordinate of 22:05, df.loc[df['x'] == 1325]
//p2 is the value for coordinate of 22:00, df.loc[df['x'] == 1320]
p1 = (0.878652 ,-0.477463)
p2 = (0.86802 ,-0.49653)
# Difference in x coordinates
dx = p2[0] - p1[0]
# Difference in y coordinates
dy = p2[1] - p1[1]
# Angle between p1 and p2 in radians
theta = math.atan2(dy, dx)
theta * (180 / math.pi)
CodePudding user response:
- Find angle of the first point
- Find angle of the second point
- Diff of the two is the angle between two points
a1 = math.atan2(*p1)
a2 = math.atan2(*p2)
theta = a2 - a1
Using the points given, theta is ~1.25 degrees
CodePudding user response:
theta
is not math.atan2(dy, dx)
but atan2(y2, x2) - atan2(y1,x1)