def angles_from_sphere(pts):
"""equirectangular projection, ie. map from sphere in R^3 to (0, 2*pi) x (-pi/2, pi/2)
Parameters
----------
pts : array_like (3,...)
pts[0,...], pts[1,...], and pts[2,...] are x,y, and z coordinates
Returns
-------
out : ndarray (2,...)
pts transformed from x,y,z to longitude,latitude
"""
pts = np.asarray(pts) #turn into an ndarray if necessary
x,y,z = pts[0], pts[1], pts[2]
out = np.empty((2,) + pts.shape[1:])
#longitude:
out[0] = np.arctan2(y,x)
out[0] %= 2*pi #wrap negative values around the circle to positive
#latitude:
r = np.hypot(x,y)
out[1] = np.arctan2(z,r)
return out
sphere_transforms_numpy.py 文件源码
python
阅读 28
收藏 0
点赞 0
评论 0
评论列表
文章目录