我有TOAST projection大小为n
的行星地图的图像,其中n
是2的幂。我想在TOAST地图上拍摄一个像素,并计算球体上相应点的纬度/经度。
我有以下功能,但似乎不起作用。
def _x_y_to_lat_lon((x, y), size):
quad = size / 2
if x >= quad:
x -= quad
if y >= quad:
quadrant = 1
y -= quad
else:
quadrant = 2
y = (quad - 1 - y)
else:
x = (quad - 1 - x)
if y >= quad:
quadrant = 0
y -= quad
else:
quadrant = 3
y = (quad - 1 - y)
x += 1
y += 1
ax = abs(x)
ay = abs(y)
if ax + ay > size:
hemisphere = -1
else:
hemisphere = 1
latitude = (ax + ay) / size * pi * hemisphere
longitude = (ax - ay) / (ax + ay) * pi / 2 * hemisphere + (pi / 4) + (quadrant * pi / 2)
return latitude, longitude
答案 0 :(得分:2)
为了便于参考,以下是我如何安排八分圆:
from math import atan2, degrees
def toast_xy_to_latlon(x, y, size, inside=False):
"""
Given TOAST x,y coordinates into a size*size HTM
return lat, lon
where -90 <= lat <= 90 (degrees North)
and 0 <= lon <= 360 (degrees East)
"""
half = size / 2
# Figure out which quadrant (x, y) is in;
# save longitude offset and cast to first quadrant
# in new pixel-centered (u, v) coordinate system
# where 0.5 <= u,v <= half - 0.5 and (0,0) is North
if x < half:
if y < half:
# 6,7
lon_offset = 270
u,v = half - x - 0.5, half - y - 0.5
else:
# 0,1
lon_offset = 0
u,v = y + 0.5 - half, half - x - 0.5
else:
if y < half:
# 4,5
lon_offset = 180
u,v = half - y - 0.5, x + 0.5 - half
else:
# 2,3
lon_offset = 90
u, v = x + 0.5 - half, y + 0.5 - half
# Find latitude
lat = 90 * (1 - (u + v) / half)
# Find longitude
if u + v <= half:
# Northern hemisphere
lon = degrees(atan2(u, v))
else:
# Southern hemisphere
lon = degrees(atan2(half - v, half - u))
# Correct longitude offset -
# outside projection longitudes are measured CCW from left,
# inside projections CCW from right (rotated 180 degrees)
if inside:
lon_offset = (lon_offset + 180) % 360
return lat, lon + lon_offset
答案 1 :(得分:0)
第二种解决方案也不完全正确。它给出了奇怪的非线性经度。大约45度,135度,225度和315度的经度过度膨胀,经度为0,90,180和270度的太多。原因是假设TOAST投影中的经度是角度等于atan2(u / v)这是不正确的。经度是具有恒定纬度的线的距离,而不是角度。见草图。
如果TOAST投影的原点(0,0)位于中间且X:= V且Y:= V并且均为正值,那么草图中星形的RA,DEC则为:
纬度或天空下降:=(y + x-1)* pi / 2;
经度或天空right_ascension:= 0.5 * pi *(1-x /(y + x));
对TOAST投影中的所有8个三角形应用此公式,每次正确校正如下:
(1)首先使X,Y为正,并且在极点范围内[0..1]。
(2)申请上述公式
(3)每次为每个三角形应用Lon / DEC和lat / RA校正/移位。
注意到Microsoft TOAST程序没有在极点附近产生直线偏角/纬线。我的例行公事。