Convert Cartesian coordinates to spherical coordinates
Source:R/linear-spherical-spline.R
      cartesian_to_spherical.RdThis function converts Cartesian coordinates to spherical coordinates.
Details
The Cartesian coordinates (x, y, z) are converted to spherical coordinates (theta, phi). Theta represents the inclination angle (0 to pi), and phi represents the azimuth angle (0 to 2*pi).
Examples
#example1
cartesian_points1 <- matrix(c(1/sqrt(3), 1/sqrt(3), 1/sqrt(3),-1/sqrt(3), 1/sqrt(3), -1/sqrt(3)),
  ncol = 3, byrow = TRUE)
cartesian_to_spherical(cartesian_points1)
#>          theta       phi
#> [1,] 0.9553166 0.7853982
#> [2,] 2.1862760 2.3561945
#example2
cartesian_points2 <- matrix(c(1, 0, 0, 0, 1, 0, 0, 0, 1),ncol = 3, byrow = TRUE)
cartesian_to_spherical(cartesian_points2)
#>         theta      phi
#> [1,] 1.570796 0.000000
#> [2,] 1.570796 1.570796
#> [3,] 0.000000 0.000000