lux*_*cem 4 python opengl pygame map-projections
我有这个图像:
我不知道究竟是什么样的投影,我猜是形状的equirectangular或mercator.这是态度指标的纹理,b.
我想根据由两个角度(航向和俯仰)定义的方向向量绘制正投影,b或者可能是一个普通透视投影(哪个看起来更好).此方向定义球体上的一个点,此点应该是投影的中心.
我希望它从飞行员的角度来看,因此只应绘制一半的球体.
我使用python,我还没有选择图形库,但我可能会使用pygame.
我找到了相关的东西:http://www.pygame.org/project-Off-Center+Map+Projections-2881-.html但是它使用的是OpenGL而我没有使用它的经验,但我可以尝试,如果需要的话.
我该怎么办?我可能可以通过计算计算公式中的每个像素来手动绘制它,但我认为有一些库工具可以有效地做到这一点(硬件加速可能?).
对于全Python解决方案(使用numpy/scipy数组操作,这将比任何显式的每像素循环更快),这:
#!/usr/bin/env python
import math
import numpy as np
import scipy
import scipy.misc
import scipy.ndimage.interpolation
import subprocess
src=scipy.misc.imread("ji80w.png")
size=256
frames=50
for frame in xrange(0,frames):
# Image pixel co-ordinates
px=np.arange(-1.0,1.0,2.0/size)+1.0/size
py=np.arange(-1.0,1.0,2.0/size)+1.0/size
hx,hy=scipy.meshgrid(px,py)
# Compute z of sphere hit position, if pixel's ray hits
r2=hx*hx+hy*hy
hit=(r2<=1.0)
hz=np.where(
hit,
-np.sqrt(1.0-np.where(hit,r2,0.0)),
np.NaN
)
# Some spin and tilt to make things interesting
spin=2.0*np.pi*(frame+0.5)/frames
cs=math.cos(spin)
ss=math.sin(spin)
ms=np.array([[cs,0.0,ss],[0.0,1.0,0.0],[-ss,0.0,cs]])
tilt=0.125*np.pi*math.sin(2.0*spin)
ct=math.cos(tilt)
st=math.sin(tilt)
mt=np.array([[1.0,0.0,0.0],[0.0,ct,st],[0.0,-st,ct]])
# Rotate the hit points
xyz=np.dstack([hx,hy,hz])
xyz=np.tensordot(xyz,mt,axes=([2],[1]))
xyz=np.tensordot(xyz,ms,axes=([2],[1]))
x=xyz[:,:,0]
y=xyz[:,:,1]
z=xyz[:,:,2]
# Compute map position of hit
latitude =np.where(hit,(0.5+np.arcsin(y)/np.pi)*src.shape[0],0.0)
longitude=np.where(hit,(1.0+np.arctan2(z,x)/np.pi)*0.5*src.shape[1],0.0)
latlong=np.array([latitude,longitude])
# Resample, and zap non-hit pixels
dst=np.zeros((size,size,3))
for channel in [0,1,2]:
dst[:,:,channel]=np.where(
hit,
scipy.ndimage.interpolation.map_coordinates(
src[:,:,channel],
latlong,
order=1
),
0.0
)
# Save to f0000.png, f0001.png, ...
scipy.misc.imsave('f{:04}.png'.format(frame),dst)
# Use imagemagick to make an animated gif
subprocess.call('convert -delay 10 f????.png anim.gif',shell=True)
Run Code Online (Sandbox Code Playgroud)
会得到你
.
OpenGL确实是进行这种像素争论的地方,特别是如果它适用于任何交互式的东西.
归档时间: |
|
查看次数: |
2165 次 |
最近记录: |