Note
Go to the end to download the full example code.
Cartesian to Spherical Conversion Example#
Convert Cartesian coordinates to spherical coordinates (theta, phi).
Input Cartesian points:
[[ 0.57735027 0.57735027 0.57735027]
[-0.57735027 0.57735027 -0.57735027]]
Output spherical coordinates (theta, phi):
[[0.95531662 0.78539816]
[2.18627604 2.35619449]]
import numpy as np
from spheresmooth import cartesian_to_spherical
# Example 1 data
cartesian_points1 = np.array([
[1/np.sqrt(3), 1/np.sqrt(3), 1/np.sqrt(3)],
[-1/np.sqrt(3), 1/np.sqrt(3), -1/np.sqrt(3)],
])
print("Input Cartesian points:")
print(cartesian_points1)
theta_phi = cartesian_to_spherical(cartesian_points1)
print("\nOutput spherical coordinates (theta, phi):")
print(theta_phi)
Total running time of the script: (0 minutes 0.001 seconds)