一、概述
- 主要內容:本文基于GeographicLib開源庫,實現了一個地理空間坐標轉換功能,主要用于根據觀測站的位置和目標的相對方位信息,計算目標在地球坐標系中的絕對位置。
- 輸入:觀測站的經緯度坐標(緯度、經度、海拔高度)和目標的相對觀測參數(方位角、俯仰角、距離)
- 輸出:目標在地心固定坐標系(ECEF)中的三維坐標(X,Y,Z)
二、代碼
#include <iostream>
#include <iomanip>
#include <cmath>
#include <GeographicLib/Geocentric.hpp>
#include <GeographicLib/LocalCartesian.hpp>#ifndef M_PI
#define M_PI (3.14159265358979323846)
#endifvoid calculateTargetPosition(double station_lat, double station_lon, double station_alt,double azimuth, double elevation, double distance,double& target_x, double& target_y, double& target_z) {// 驗證輸入參數if (distance <= 0) {std::cerr << "錯誤:距離必須為正數" << std::endl;return;}// 初始化局部坐標系GeographicLib::LocalCartesian proj(station_lat, station_lon, station_alt,GeographicLib::Geocentric::WGS84());// 計算局部ENU坐標(東北天)double east = distance * cos(elevation) * sin(azimuth);double north = distance * cos(elevation) * cos(azimuth);double up = distance * sin(elevation);// 轉換為地心固定坐標系下的經緯高double lat=0., lon=0., alt=0.;proj.Reverse(east, north, up, lat, lon, alt);// 轉換為地心固定坐標系下的XYZconst GeographicLib::Geocentric& earth = GeographicLib::Geocentric::WGS84();earth.Forward(lat, lon, alt, target_x, target_y, target_z);
}int main() {// 示例:站址坐標(緯度,經度,高度)double station_lat = 40.0; // 北緯40度double station_lon = 116.0; // 東經116度double station_alt = 100.0; // 海拔100米// 觀測目標參數double azimuth = 206.043782 * M_PI/180.0; // 方位角double elevation = 15.318917 * M_PI/180.0; // 俯仰角double distance = 929807.813; // 距離(米)// 計算結果double target_x, target_y, target_z;calculateTargetPosition(station_lat, station_lon, station_alt,azimuth, elevation, distance,target_x, target_y, target_z);std::cout << std::fixed << std::setprecision(3) << "Target ECEF (X,Y,Z): "<< target_x << ", "<< target_y << ", "<< target_z << std::endl;return 0;
}
三、運行結果
在Windows/GeographicLib-2.1.1環境下,上述代碼程序運行輸出結果如下(正確性已驗證):
Target ECEF (X,Y,Z): -2100493.586, 5204826.766, 3618737.188
四、GeographicLib庫簡單介紹?
1、GeographicLib 功能定位
- GeographicLib 庫聚焦于?地表及近地空間的地理計算和地固坐標系轉換(如地心地固坐標系ECEF、大地坐標系BLH)?,未包含天球慣性坐標系(如 J2000)的轉換功能。J2000 轉換依賴歲差章動、恒星時等動態天文參數,需實時地球定向數據(EOP),而GeographicLib 未集成此類模型。?
- 其官方網址為: https://geographiclib.sourceforge.io
2、GeographicLib 的核心能力
(1)?大地測量計算?
- ? ? 大圓距離與方位角計算(如兩點間測地線距離、多個點包圍的球面面積)
- ? ? 測地線路徑規劃(如航線生成)
- ? ? 地表曲率、子午線弧長等橢球模型計算
(2)坐標系統轉換?
- ? ? ?經緯高(BLH)?地固直角坐標(ECEF)?(支持 WGS84、GRS80 等橢球體)
- ? ? ?局部坐標系轉換?(如ENU/NED與ECEF互轉)
- ? ? 投影坐標系轉換(UTM、UPS、MGRS)
(3)地球物理模型?
- ? ? 重力場計算(如 EGM2008 模型)
- ? ? 地磁場模擬(如 WMM2020 模型)