这似乎是一个很容易的任务,但我没有找到一个解决办法,我已经用尽的想法。你知道吗
我用两个角度来定义一些变换系数。现在,我没有实际数据中这些角度的值,我有系数,我需要恢复这些角度。你知道吗
我原以为^{a1
角度,而是返回其180
补码,这会影响a2
角度的恢复。你知道吗
我做错了什么?如何正确恢复a1, a2
角度?你知道吗
import numpy as np
# Repeat 100 times
for _ in range(100):
# Define two random angles in the range [-pi, pi]. I do not have these
# angles in my actual data, I have the A,B,C coefficients shown below.
a1, a2 = np.random.uniform(-180., 180., (2,))
# Transformation coefficients using the above angles.
# This is the data I actually have.
a1_rad, a2_rad = np.deg2rad(a1), np.deg2rad(a2) # to radians
A = - np.sin(a1_rad) * np.sin(a2_rad)
B = np.cos(a1_rad) * np.sin(a2_rad)
C = np.cos(a2_rad)
# Recover a1 using 'arctan2' (returns angle in the range [-pi, pi])
a1_recover = np.arctan2(-A / B, 1.)
# Now obtain sin(a2), used below to obtain 'a2'
sin_a2 = -A / np.sin(a1_recover)
# Recover a2 using 'arctan2', where: C = cos(a2)
a2_recover = np.arctan2(sin_a2, C)
# Print differences.
a1_recover = np.rad2deg(a1_recover)
print("a1: {:.2f} = {} - {}".format(a1 - a1_recover, a1, a1_recover))
a2_recover = np.rad2deg(a2_recover)
print("a2: {:.2f} = {} - {}\n".format(a2 - a2_recover, a2, a2_recover))
你应该使用np.arctan2号(-A,B)代替np.arctan2号(-A/B,1.)。对于后者,您将丢失信息:A=-1和B=1将给出与A-1和B=-1相同的结果,因此有时180不匹配。 如果将a2限制在(0180)中,则可以恢复角度。注意,有了这个限制,a2可以恢复为acos(C)。(我试过这个,但由于我的程序是C语言的,所以可能没有帮助)
您无法还原角度符号信息,因为它在
A,B
计算(形成)中丢失。你知道吗8种可能的
sin/cos
符号组合只给出了4种A/B
符号的结果(而cos(a2)
符号在这里没有帮助)。你知道吗注意,对于球坐标,倾角范围仅为
0..Pi
当
a2_rad
等于0时,(A, B, C)
等于(0, 0, 1)
,无论a1_rad
等于什么。所以这个变换不是1比1。因此没有明确定义的逆。你知道吗类似的问题也发生在相对的南极。在浮点精度的限制范围内,所有这些值(形式为
ABC(a1, 180)
)也基本相等:你可以把
a1
,a2
看作单位球上的坐标,其中a1
表示远离x轴的角度(通常称为theta
)和a2
表示远离z轴的角度(通常称为phi
)。你知道吗A
,B
,C
表示笛卡尔坐标系中单位球面上的同一点。你知道吗通常spherical coordinates将
a1
限制在[0, 2*pi)
范围内,将a2
限制在[0, pi]
范围内。 即使有这个限制,北极和南极也有不止一个(实际上是无限多个)有效的表示。你知道吗相关问题 更多 >
编程相关推荐