Using Matlab to convert geodetic coordinates and geodetic rectangular coordinates in geodesy

I. Overview

The geodetic coordinate system is a coordinate system in which the longitude L of the earth, the latitude B of the earth and the height H of the earth represent the geometric position of a point in space. The longitude of the earth is measured from the meridian of the starting earth, measured eastwards from 0 ° to 360 °; it can also be measured eastwards and westwards, each from 0 ° to 180 °, called east longitude and west longitude, respectively, and east longitude is positive, West longitude is negative.
The angle between the normal of a point and the equatorial plane is called the geodetic latitude of the point, and is denoted by B. The latitude of the earth is measured from the equatorial plane, and is measured from the south and north poles, each from 0 ° to 90 °. They are called south latitude and north latitude, respectively. The north latitude is positive and the south latitude is negative.
The distance from the ground point along the normal to the reference ellipsoid is called the ground height of the point, and is represented by the letter H. The height of the earth is calculated from the ellipsoidal surface, positive outwards and negative inwards.
The geodetic space rectangular coordinate system takes the center O of the ellipsoid as the origin of the coordinate, the intersection of the starting meridian plane and the equatorial plane as the X axis, the direction orthogonal to the X axis on the equatorial plane is the Y axis, and the rotation axis of the ellipsoid is The Z axis constitutes the right-handed coordinate system O-XYZ.

Insert picture description here
Figure 1 Geodetic coordinate system and geodetic space rectangular coordinate system

2. Geodetic coordinates of known points (B, L, H) Calculate the spatial rectangular coordinates of points (X, Y, Z)

Formula required:
X = (N + H) cos (B) cos (L)
Y = (N + H) cos (B) sin (L)
Z = [N (1-e 2 ) + H] * sin ( B)
where N is the normal length N = a / W
W is an auxiliary formula W = sqrt ((1-e 2 ) sin 2 B)

Calculation requirements: In
this example, the GRS80 ellipsoidal parameters are used for calculation, and the final result is output to the screen in meters, and 3 decimal places are retained
(the degree, minute, second, and radian functions are first written)

The matlab source program is as follows:

Degrees, minutes, seconds to radians function

function rad=d2r(deg,min,sec)
    %    角度转弧度
    rad=(deg+min/60+sec/3600)*pi/180;

Main program

clear
clc
b=d2r(33,44,55.666);
l=d2r(77,11,22.333);
h=5555.660;   %经纬度
a=6378137;f=1/298.257222101;e2=2*f-f^2;   %GRS80椭球参数
W=sqrt(1-e2*(sin(b))^2);
N=a/W;
X=(N+h)*cos(b)*cos(l);
Y=(N+h)*cos(b)*sin(l);
Z=(N*(1-e2)+h)*sin(b);
fprintf('\nX=%.3fm\nY=%.3fm\nZ=%.3fm\n',X,Y,Z);

2. Know the geodetic space rectangular coordinates (X, Y, Z) to calculate the geodetic coordinates (B, L, H)

The required formula:
tan (L) = Y / X, then L = atan (Y / X)
tan (B) = 1 / sqrt (X 2 + Y 2 ) * (Z + ae 2 tanB / sqrt (1 + tan 2 B-e 2 tan 2 B))
Here it is necessary to use an iterative algorithm to calculate the value of B, first take an initial value tan (B0) = Z / sqrt (X 2 + Y 2 ) The
convergence condition is the absolute value of tanB twice The difference is less than 5 × 10 -10 (that is, the difference between the absolute values ​​of B calculated twice is less than 0.0001 ″), and the iteration can be stopped

H = Z / sinB-N (1-e 2 )
where N is the normal length N = a / W
W is an auxiliary formula W = sqrt ((1-e 2 ) sin 2 B)

Calculation requirements: In
this example, the CGCS2000 ellipsoid parameters are used for calculation, and the degree is displayed as a decimal, that is,
B = 30 ° 12′29 ″ is displayed as B = 30.122900000 (seconds retain 5 decimal places) and
elevation reserves 3 decimal places
(first to be written Radian to angle function)

The matlab source program is as follows:

Radian to angle and determine the output format

function deg=r2d(rad)
    %   弧度转角度
    rad1=rad*180/pi;
    deg1=fix(rad1);
    min=fix((rad1-deg1)*60);
    sec=((rad1-deg1)*60-min)*60;
    deg=deg1+min/100+sec/10000;

Main program

clear
clc
X=-2109101.506+500*29;
Y=4843022.866+500*29;
Z=3562987.896+500*29;     %空间直角坐标
a=6378137;f=1/298.257222101;e2=2*f-f^2;    %CGCS2000椭球参数
l=atan(Y/X);
L=r2d(l);
tanb0=Z/(sqrt(X^2+Y^2));
tanb1=(1/sqrt(X^2+Y^2))*(Z+(a*e2*tanb0)/(sqrt(1+tanb0^2-e2*tanb0^2)));
while abs(tanb1-tanb0)>=1e-7
    tanb0=tanb1;
    tanb1=(1/sqrt(X*X+Y*Y))*(Z+(a*e2*tanb0)/(sqrt(1+tanb0^2-e2*tanb0^2)));
end
b=atan(tanb1);
B=r2d(b);
W=sqrt(1-e2*(sin(b)^2));
N=a/W;
H=(sqrt(X^2+Y^2)/cos(b))-N;
fprintf('\nB=%.9f\nL=%.9f\nH=%.3f\n',B,L,H);

Please correct me if there are any mistakes

Published 13 original articles · Like 32 · Visits 10,000+

Guess you like

Origin blog.csdn.net/weixin_43637490/article/details/89371315