在 python 中求圆上两点的角度

Finding angles two points on circle in python

我正在尝试找出两个圆坐标之间的角度。这些圆坐标是从 24 小时时间数据转换而来的。

问题是当我计算时间 22:00 和 22:05 之间的角度时,它显示为 60 度,这很奇怪,因为两个时间之间只有 5 分钟的差异,所以它不应该显示 60 度角。

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)

theta 不是 math.atan2(dy, dx) 而是 atan2(y2, x2) - atan2(y1,x1)