我在3D立方体内有一组点。我想根据观察者的位置在2D中获得这些点的视觉投影。到目前为止,我一直试图在3D中绘制我的点,并设置高程和方位角,以便我可以在一侧观察立方体。在Matplotlib中设置查看位置3d散点图
这是一个简单的例子,但我需要能够概括我的代码观察者的任何(X,Y,Z)的位置。这是我迄今为止所尝试的:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
coord = np.random.uniform(2.,4., (10000,3)) # cube points
los = np.array([10.,3.,3]) #observer position (looking at side of cube)
center = np.array([3.,3.,3.]) #cube center
def elev(los, target):
diff = target - los
cosel = np.sum(los*diff)/np.sqrt(np.sum(los**2.) * np.sum(diff**2.))
el = np.degrees(np.arccos(cosel))
return el
def azi(los, target):
diff = target - los
cosazi = (-los[2]*los[0]*diff[0] - los[2]*los[1]*diff[1] + \\
(los[0]**2.+los[1]**2)*diff[2])/np.sqrt((los[0]**2.+los[1]**2.)* \\
(los[0]**2.+los[1]**2.+los[2]**2)*(diff[0]**2.+diff[1]**2.+diff[2]**2))
sinazi = (-los[2]*diff[0] + los[0]*diff[1])/\\
np.sqrt((los[0]**2.+los[1]**2.)*(diff[0]**2.+diff[1]**2.+diff[2]**2.))
tanazi = sinazi/cosazi
azi = np.degrees(np.arctan(tanazi))
return azi
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(coord[:,0], coord[:,1], coord[:,2], edgecolor = "none", alpha = 0.3)
ax.view_init(elev=elev(los, center), azim=azi(los,center))
plt.show()
我应该看到一个完美的广场,但我的观点是一个角度。出了什么问题?
我已经借了仰角和方位角公式从这里:https://gis.stackexchange.com/questions/58923/calculate-view-angle