从 Google 地图上的当前位置到太阳的方向

Direction from current location on Google Maps to the Sun

我目前能够计算给定日期时间的太阳高度和方位角,现在我希望能够从 Google 地图上的任何当前位置指向太阳(基于高度坐标和方位角)。

我正在开发一个应用程序,它可以向用户显示从用户当前位置到太阳的方向。

非常欢迎任何想法。

给定地理坐标 lat(北为正)和 long(东为正),地球上的 3D 坐标为(一种可能性):

    / x \   / cos(lat) * sin(long) \
p = | y | = | cos(lat) * cos(long) |
    \ z /   \ sin(lat)             /

那么北方向是:

        / -sin(lat) * sin(long) \
north = | -sin(lat) * cos(long) |
        \  cos(lat)             /

而东方向是:

       /  cos(lat) * cos(long) \
east = | -cos(lat) * sin(long) |
       \  0                    /

给定方位角和高度,您可以获得 3D 方向:

dir = (-cos(azimuth) * north -sin(azimuth) * east) * cos(altitude) + sin(altitude) * p

因此,对于任何正标量 t,您可以计算出您在地球上的位置与物体之间的点:

pos(t) = p + t * dir

您可以通过归一化将位置投影回地球:

pos_normalized(t) = pos(t) / ||pos(t)||

,其中 ||pos(t)||pos(t) 的长度。

鉴于此,您可以计算纬度和经度:

lat2 = asin(pos_normalized(t).z)
long2 = atan2(pos_normalized(t).x, pos_normalized(t).y)

这是一个位于太阳方向的点。选择一些足够小的t来计算(应该比1小很多,单位基本上是地球半径的倍数)。对于某些地图,所有这些位置可能位于一条线上。但是,这不能保证任意地图。因此,您可能想要对几个点进行采样并生成折线。