Created
May 20, 2015 15:14
-
-
Save mvdoc/8f8ea5a421b4ba09b0bf to your computer and use it in GitHub Desktop.
fast cartesian to polar conversion, from https://stackoverflow.com/questions/4116658/faster-numpy-cartesian-to-spherical-coordinate-conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def appendSpherical_np(xyz): | |
ptsnew = np.hstack((xyz, np.zeros(xyz.shape))) | |
xy = xyz[:,0]**2 + xyz[:,1]**2 | |
ptsnew[:,3] = np.sqrt(xy + xyz[:,2]**2) | |
ptsnew[:,4] = np.arctan2(np.sqrt(xy), xyz[:,2]) # for elevation angle defined from Z-axis down | |
#ptsnew[:,4] = np.arctan2(xyz[:,2], np.sqrt(xy)) # for elevation angle defined from XY-plane up | |
ptsnew[:,5] = np.arctan2(xyz[:,1], xyz[:,0]) | |
return ptsnew |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment