兩個不同的三維空間直角座標系之間轉換時,通常使用七參數模型(數學方程組)。在該模型中有七個未知參數,即:
(1)三個座標平移量(△X,△Y,△Z),即兩個空間座標系的座標原點之間座標差值;
(2)三個座標軸的旋轉角度(△α,△β,△γ),通過按順序旋轉三個座標軸指定角度,可以使兩個空間直角座標系的XYZ軸重合在一起。
(3)尺度因子K,即兩個空間座標系內的同一段直線的長度比值,實現尺度的比例轉換。通常K值幾乎等於1。 以上七個參數通常稱爲七參數。運用七參數進行的座標轉換稱爲七參數座標轉換。
下面來看布爾沙模型計算,算法來源proj4j-0.1.1.jar
七參數正算
public void transformToGeocentricFromWgs84(ProjCoordinate p) {
if (this.transform.length == 3)
{
p.x -= this.transform[0];
p.y -= this.transform[1];
p.z -= this.transform[2];
}
else if (this.transform.length == 7)
{
double Dx_BF = this.transform[0];
double Dy_BF = this.transform[1];
double Dz_BF = this.transform[2];
double Rx_BF = this.transform[3];
double Ry_BF = this.transform[4];
double Rz_BF = this.transform[5];
double M_BF = this.transform[6];
double x_tmp = (p.x - Dx_BF) / M_BF;
double y_tmp = (p.y - Dy_BF) / M_BF;
double z_tmp = (p.z - Dz_BF) / M_BF;
p.x = (x_tmp + Rz_BF * y_tmp - Ry_BF * z_tmp);
p.y = (-Rz_BF * x_tmp + y_tmp + Rx_BF * z_tmp);
p.z = (Ry_BF * x_tmp - Rx_BF * y_tmp + z_tmp);
}
}
七參數反算
public void transformFromGeocentricToWgs84(ProjCoordinate p)
{
if (this.transform.length == 3)
{
p.x += this.transform[0];
p.y += this.transform[1];
p.z += this.transform[2];
}
else if (this.transform.length == 7)
{
double Dx_BF = this.transform[0];
double Dy_BF = this.transform[1];
double Dz_BF = this.transform[2];
double Rx_BF = this.transform[3];
double Ry_BF = this.transform[4];
double Rz_BF = this.transform[5];
double M_BF = this.transform[6];
double x_out = M_BF * (p.x - Rz_BF * p.y + Ry_BF * p.z) + Dx_BF;
double y_out = M_BF * (Rz_BF * p.x + p.y - Rx_BF * p.z) + Dy_BF;
double z_out = M_BF * (-Ry_BF * p.x + Rx_BF * p.y + p.z) + Dz_BF;
p.x = x_out;
p.y = y_out;
p.z = z_out;
}
}