cartesian to spherical coordinates (angles in radians)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | x |
x = r cos(phi) cos (theta) |
||
real(kind=wp), | intent(in) | :: | y |
y = r cos(phi) sin(theta) |
||
real(kind=wp), | intent(in) | :: | z |
z = r sin(phi) |
||
real(kind=wp), | intent(out) | :: | rho |
distance |
||
real(kind=wp), | intent(out) | :: | theta |
longitude |
||
real(kind=wp), | intent(out) | :: | phi |
latitude |
pure subroutine sphere (x, y, z, rho, theta, phi) implicit none real(wp), intent (in) :: x !! x = r cos(phi) cos (theta) real(wp), intent (in) :: y !! y = r cos(phi) sin(theta) real(wp), intent (in) :: z !! z = r sin(phi) real(wp), intent (out) :: rho !! distance real(wp), intent (out) :: theta !! longitude real(wp), intent (out) :: phi !! latitude real(wp) :: r theta = zero phi = zero rho = sqrt (x*x+y*y+z*z) r = sqrt (x*x+y*y) if (r /= zero) then theta = modulo (atan2(y, x), twopi) phi = atan2 (z, r) end if end subroutine sphere