大地座標轉換極座標(球座標)

作業順便記錄一下,場面監視
1.兩個函數一個是大地座標轉換球座標Geodetic_to_spherical;一個是球座標轉換大地座標spherical_to_Geodetic。
2.WGS84座標系的參數:長半軸r=6378137,橢球扁率:f=1/298.257223563,短半軸b=r*(1-f),第一輔助係數W通過公式W=√(1-e²sin²B) B爲緯度。橢圓曲率半徑N=a/W
3.空間直角座標原點和球座標原點均取在地球球心
4.極座標第三參量取角度,認爲是球座標

一.WGS84大地到球座標

  • 大地轉換空間直角座標(座標軸原點取地心)

大地座標表示爲:緯度B、經度L、海拔H
空間直角座標表示方法:X、Y、Z

  • 空間按直角轉球座標

在這裏插入圖片描述

定義徑向距離r,天頂角sita ,方位角fai
在這裏插入圖片描述

二.球座標到大地座標

1.


Python代碼

##1.兩個函數一個是大地座標轉換球座標Geodetic_to_spherical;一個是球座標轉換大地座標spherical_to_Geodetic。
import math

#######################大地轉換球座標####################################
def Geodetic_to_spherical(latitude,longitude,altitude):
	B=math.radians(latitude);
	L=math.radians(longitude);
	H=altitude;
	f=1/298.257223563;
	r=6378137;
	b=r*(1-f);
	e=math.sqrt(2*f-f*f);
	N=r/math.sqrt(1-e*e*math.sin(B)*math.sin(B));
#大地座標轉空間直角座標存放到data數組中
	data =[(N+H)*math.cos(B)*math.cos(L),(N+H)*math.cos(B)*math.sin(L),(N*(1-e*e)+H)*math.sin(B)];
#直角座標住那換球座標存放到data_spherical數組中
	data_spherical = [math.sqrt(data[0]*data[0]+data[1]*data[1]+data[2]*data[2]),\
				 math.atan(math.sqrt(data[0]*data[0]+data[1]*data[1])/data[2])*180/math.pi,\
				 math.atan(data[1]/data[0])*180/math.pi]; #空間直角座標xyz轉換成球座標 r sita fai

	return data_spherical

##########################球轉大地#########################################
def spherical_to_Geodetic(r,p,f):
	f=1/298.257223563;
	r=6378137;
	b=r*(1-f);
	e=math.sqrt(2*f-f*f);
	e2 = (1/(1-e))-1;
###得到空間直角座標xyz存到數組data【0~2】中
	data = [r*math.sin(p)*math.cos(f),r*math.sin(p)*math.sin(f),r*math.cos(p)]
	ppp = math.atan(data[2]*r/(b*math.sqrt(data[0]*data[0]+data[1]*data[1])))
###存放大地座標的數組data_Geodetic 【0~2】對應L B H
	data_Geodetic = [0,0,0]
#  大地座標L=data_Geodetic[0]
	data_Geodetic[0] = math.atan(data[1]/data[0])
#  大地座標B=data_Geodetic[1]
	data_Geodetic[1] = math.atan((data[2]+e2*e2*b*math.sin(ppp)*math.sin(ppp)*math.sin(ppp))/(math.sqrt(data[0]*data[0]+data[1]*data[1])-e*e*r*math.cos(ppp)*math.cos(ppp)*math.cos(ppp)))
	B=data_Geodetic[1]
	N = r / math.sqrt(1 - e * e * math.sin(B) * math.sin(B));
#  大地座標H=data_Geodetic[2]
	data_Geodetic[2] = (math.sqrt(data[0]*data[0]+data[1]*data[1])/math.cos(B))-N

	return data_Geodetic

#a1存放待轉換的大地座標
a1=[100,101,1500]
a = Geodetic_to_spherical(a1[0],a1[1],a1[2])

#b1存放待轉換的大地座標
b1= [6359000, 22, 33]
b = spherical_to_Geodetic(b1[0],b1[1],b1[2])

print('輸入大地座標[L,B,H]:',a1,'  輸出的球座標爲[r,sita,fai]:',a)
print('\n')
print('輸入球座標[r,sita,fai]:',b1,'  輸出的大地座標[L,B,H]爲:',b)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章