python實現經緯度取樣的示例程式碼
阿新 • • 發佈:2020-12-11
原理
經度 phi,緯度 theta 處的座標為:
x =R* cos(phi) * cos(theta)
y = Rsin(phi) * cos(theta)
z = Rsin(theta)
問題
經緯度取樣的取樣點是相同經緯度間隔的交點。但是取樣1000個點,如何劃分多少條經線,多少條緯線相交,才能使1000個取樣點最均勻的分佈在球面上(雖然經緯度取樣本來就不均勻,但對於不同的取樣點個數應該有一種相對最均勻的經緯線劃分)?求大佬指教!
我目前是將緯度每10度進行劃分。
Code
import random from mpl_toolkits import mplot3d import numpy as np import math import matplotlib.pyplot as plt %matplotlib inline ax=plt.axes(projection="3d") N=1000 x=[] y=[] z=[] r=1 #經度 def longitude(lng): phi=(180+lng)*(math.pi/180) return phi #緯度 def latitude(lat): theta=lat*(math.pi/180) return theta for i in range(-80,90,10): for j in np.arange(-180,180,360/((N-2)/17)): #x.append(-r*math.sin(latitude(i))*math.cos(longitude(j))) #y.append(r*math.cos(latitude(i))) #z.append(r*math.sin(latitude(i))*math.sin(longitude(j))) x.append(r*math.cos(latitude(i))*math.cos(longitude(j))) z.append(r*math.sin(latitude(i))) y.append(r*math.cos(latitude(i))*math.sin(longitude(j))) x.append(r*math.cos(latitude(-90))*math.cos(longitude(0))) z.append(r*math.sin(latitude(-90))) y.append(r*math.cos(latitude(-90))*math.sin(longitude(0))) x.append(r*math.cos(latitude(90))*math.cos(longitude(0))) z.append(r*math.sin(latitude(90))) y.append(r*math.cos(latitude(90))*math.sin(longitude(0))) xline=np.array(x) yline=np.array(y) zline=np.array(z) print(xline.shape) ax.scatter3D(xline,yline,zline,s=2) plt.savefig("D:\\samples\\經緯度取樣.png")
效果
到此這篇關於python實現經緯度取樣的示例程式碼的文章就介紹到這了,更多相關python 經緯度取樣內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!