1.代码
function [target_lat, target_lon, target_alt] = relative2geodetic(ref_lat, ref_lon, ref_alt, east_offset, north_offset, up_offset) % 将相对偏移转换为地理坐标系 % 输入: % ref_lat, ref_lon, ref_alt - 参考点的纬度、经度、高度(度, 度, 米) % east_offset, north_offset, up_offset - 东向、北向、垂直偏移量(米) % 输出: % target_lat, target_lon, target_alt - 目标点的纬度、经度、高度% 地球参数(WGS84椭球体)a = 6378137.0; % 地球长半轴(米)f = 1/298.257223563; % 扁率e2 = 2*f - f*f; % 第一偏心率平方% 将参考点经纬度转换为弧度lat_rad = deg2rad(ref_lat);lon_rad = deg2rad(ref_lon);% 计算子午圈曲率半径和卯酉圈曲率半径N = a / sqrt(1 - e2 * sin(lat_rad)^2);M = a * (1 - e2) / (1 - e2 * sin(lat_rad)^2)^(3/2);% 计算经纬度变化量dlat = rad2deg(north_offset / M);dlon = rad2deg(east_offset / (N * cos(lat_rad)));% 计算目标点坐标target_lat = ref_lat + dlat;target_lon = ref_lon + dlon;target_alt = ref_alt + up_offset; end
2.测试
fprintf('=== 示例1:基本转换 ===\n');% % 参考点坐标(北京天安门) % ref_lat = 39.9087; % 纬度(度) % ref_lon = 116.3975; % 经度(度) % ref_alt = 50.0; % 高度(米) % % % 相对偏移量(米) % east_offset = 1000; % 东向偏移 % north_offset = 500; % 北向偏移 % up_offset = 10; % 垂直偏移 % % % 转换为地理坐标 % [target_lat, target_lon, target_alt] = relative2geodetic(... % ref_lat, ref_lon, ref_alt, east_offset, north_offset, up_offset); % % fprintf('参考点: (%.6f°N, %.6f°E, %.2fm)\n', ref_lat, ref_lon, ref_alt); % fprintf('相对偏移: 东%.1fm, 北%.1fm, 上%.1fm\n', east_offset, north_offset, up_offset); % fprintf('目标点: (%.6f°N, %.6f°E, %.2fm)\n\n', target_lat, target_lon, target_alt);% 参考点坐标(北京天安门) ref_lat = 0; % 纬度(度) ref_lon = 0; % 经度(度) ref_alt = 0; % 高度(米)% 相对偏移量(米) east_offset = 1000; % 东向偏移 north_offset = 1000; % 北向偏移 up_offset = 1000; % 垂直偏移% 转换为地理坐标 [target_lat, target_lon, target_alt] = relative2geodetic(...ref_lat, ref_lon, ref_alt, east_offset, north_offset, up_offset);fprintf('参考点: (%.6f°N, %.6f°E, %.2fm)\n', ref_lat, ref_lon, ref_alt); fprintf('相对偏移: 东%.1fm, 北%.1fm, 上%.1fm\n', east_offset, north_offset, up_offset); fprintf('目标点: (%.6f°N, %.6f°E, %.2fm)\n\n', target_lat, target_lon, target_alt);