cartesian_coords=np.array([[x1,y1,z1],[x2,y2,z2],...]) 计算球坐标的数组: 代码语言:python 代码运行次数:0 复制 r=np.linalg.norm(cartesian_coords,axis=1)theta=np.arccos(cartesian_coords[:,2]/r)phi=np.arctan2(cartesian_coords[:,1]
def _cartesian_to_spherical(self, cartesian): spherical = np.empty(cartesian.shape) spherical[:, 0] = np.linalg.norm(cartesian, axis=1) if len(self.dirmask) > 1: # 2d or 3d spherical[:, 1] = np.arctan2(cartesian[:, 1], cartesian[:, 0]) if len(self.dirmask) == 3: # 3d...
For astropy at least, some of the test I wrote for spherical to cartesian break just because of the lack of equality of sin(pi/2) to unity. Obviously, all adjustable, but it does seem that a polynomial conditioned on actually spanning the full -1 to 1 inclusive range would be nicer....
You can even do combinatorics, such as a.cross(b) to compute the Cartesian product of a and b per event, or a.choose(n) to choose n distinct combinations of elements per event. pt.choose(2) # <JaggedArray [[(54.168106, 37.744152)] [] [(53.58827, 29.811996)] ... [] [] []] ...
See also :func:`cartesian_to_spherical`. """ phi = numpy.radians(lons) theta = numpy.radians(lats) if depths is None: rr = EARTH_RADIUS else: rr = EARTH_RADIUS - numpy.array(depths) cos_theta_r = rr * numpy.cos(theta) xx = cos_theta_r * numpy.cos(phi) yy = cos_theta_r...
# save headshape to a file in mm in temporary directory tempdir = _TempDir() sphere_hsp_path = op.join(tempdir, 'test_sphere.txt') np.savetxt(sphere_hsp_path, hsp_mm) # read in raw data using spherical hsp, and extract new hsp with warnings.catch_warnings(record=True) as w: raw...