Compute the spherical polar coordinates of a point relative to a point , starting from the Cartesian coordinates of the points and
FT 14.01.2021
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
double precision, | intent(in) | :: | x |
coordinate of the point |
||
double precision, | intent(in) | :: | y |
coordinate of the point |
||
double precision, | intent(in) | :: | z |
coordinate of the point |
||
double precision, | intent(in) | :: | xo |
coordinate of the point |
||
double precision, | intent(in) | :: | yo |
coordinate of the point |
||
double precision, | intent(in) | :: | zo |
coordinate of the point |
||
double precision, | intent(out) | :: | r |
coordinate of the point , relative to |
||
double precision, | intent(out) | :: | theta |
coordinate (colatitude) of the point , relative to |
||
double precision, | intent(out) | :: | phi |
coordinate (azimuth) of the point , relative to |
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
double precision, | public | :: | xd | ||||
double precision, | public | :: | yd | ||||
double precision, | public | :: | zd |
PURE SUBROUTINE spherical_from_cartesian( x, y, z, xo, yo, zo, r, theta, phi )
!****************************************************************
!
!# Compute the spherical polar coordinates of a point \(p\)
! relative to a point \(O\), starting from the Cartesian
! coordinates of the points \(p\) and \(O\)
!
! FT 14.01.2021
!
!****************************************************************
USE constants, ONLY: pi
IMPLICIT NONE
DOUBLE PRECISION, INTENT(IN):: x
!! \(x\) coordinate of the point \(p\)
DOUBLE PRECISION, INTENT(IN):: y
!! \(y\) coordinate of the point \(p\)
DOUBLE PRECISION, INTENT(IN):: z
!! \(z\) coordinate of the point \(p\)
DOUBLE PRECISION, INTENT(IN):: xo
!! \(x\) coordinate of the point \(O\)
DOUBLE PRECISION, INTENT(IN):: yo
!! \(y\) coordinate of the point \(O\)
DOUBLE PRECISION, INTENT(IN):: zo
!! \(z\) coordinate of the point \(O\)
DOUBLE PRECISION, INTENT(OUT):: r
!! \(r\) coordinate of the point \(p\), relative to \(O\)
DOUBLE PRECISION, INTENT(OUT):: theta
!! \(\theta\) coordinate (colatitude) of the point \(p\), relative to \(O\)
DOUBLE PRECISION, INTENT(OUT):: phi
!! \(\phi\) coordinate (azimuth) of the point \(p\), relative to \(O\)
DOUBLE PRECISION:: xd, yd, zd
xd= x - xo
yd= y - yo
zd= z - zo
IF( xd > zero )THEN
phi= ATAN( yd/xd )
ELSEIF( xd < zero )THEN
phi= ATAN( yd/xd ) + pi
ELSE
phi= pi/two
ENDIF
DO WHILE(phi < zero)
phi= phi + two*pi
ENDDO
r= SQRT( xd**2 + yd**2 + zd**2 )
theta= ACOS( zd/r )
END SUBROUTINE spherical_from_cartesian