我試圖找到兩個圓坐標之間的角度。這些圓坐標是從 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)
uj5u.com熱心網友回復:
theta不是math.atan2(dy, dx)但atan2(y2, x2) - atan2(y1,x1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/449137.html
上一篇:Java計算器程式問題
下一篇:測驗整個資料框的顯著性
