Skip to main content
 首页 » 编程设计

python之试图将经度/纬度转换为笛卡尔坐标

2025年05月04日15dudu

我正在尝试将城市的经度/纬度位置转换为笛卡尔坐标,这样我就可以将其转换为像素位置以显示在 pygame 屏幕上,但我无法弄清楚。

def ConvertPoint(self, Long, Lat, height, width): 
    self.x = Long 
    self.y = Lat 
    self.x = angleToPointX(self.x, self.y, 3959) 
    self.y = angleToPointY(self.x, self.y, 3959) 
    pygame.draw.circle(self.window, (255,0,0), (int(self.x), int(self.y)), 5) 
    print(self.x, self.y) 

功能:

def angleToPointX(lat, long, magnitude=1.0): 
    V = (math.cos(lat) * math.cos(long)) 
    return V 
 
def angleToPointY(lat, long, magnitude=1.0): 
    V = (math.sin(lat)) 
    return V 

请您参考如下方法:

什么 map projection你正在用吗?纬度/经度可以直接用作圆柱投影中的 y/x - 这是玩游戏最简单的方法。否则,转换将完全取决于投影的选择。